use of org.opensearch.rest.action.RestToXContentListener in project OpenSearch by opensearch-project.
the class RestRenderSearchTemplateAction method prepareRequest.
@Override
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
// Creates the render template request
SearchTemplateRequest renderRequest;
try (XContentParser parser = request.contentOrSourceParamParser()) {
renderRequest = SearchTemplateRequest.fromXContent(parser);
}
renderRequest.setSimulate(true);
String id = request.param("id");
if (id != null) {
renderRequest.setScriptType(ScriptType.STORED);
renderRequest.setScript(id);
}
return channel -> client.execute(SearchTemplateAction.INSTANCE, renderRequest, new RestToXContentListener<>(channel));
}
use of org.opensearch.rest.action.RestToXContentListener in project OpenSearch by opensearch-project.
the class RestPutIndexTemplateAction method prepareRequest.
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
PutIndexTemplateRequest putRequest = new PutIndexTemplateRequest(request.param("name"));
if (request.hasParam("template")) {
deprecationLogger.deprecate("put_index_template_deprecated_parameter", "Deprecated parameter [template] used, replaced by [index_patterns]");
putRequest.patterns(Collections.singletonList(request.param("template")));
} else {
putRequest.patterns(Arrays.asList(request.paramAsStringArray("index_patterns", Strings.EMPTY_ARRAY)));
}
putRequest.order(request.paramAsInt("order", putRequest.order()));
putRequest.masterNodeTimeout(request.paramAsTime("master_timeout", putRequest.masterNodeTimeout()));
putRequest.create(request.paramAsBoolean("create", false));
putRequest.cause(request.param("cause", ""));
Map<String, Object> sourceAsMap = XContentHelper.convertToMap(request.requiredContent(), false, request.getXContentType()).v2();
sourceAsMap = RestCreateIndexAction.prepareMappings(sourceAsMap);
putRequest.source(sourceAsMap);
return channel -> client.admin().indices().putTemplate(putRequest, new RestToXContentListener<>(channel));
}
use of org.opensearch.rest.action.RestToXContentListener in project OpenSearch by opensearch-project.
the class RestRecoveryAction method prepareRequest.
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
final RecoveryRequest recoveryRequest = new RecoveryRequest(Strings.splitStringByCommaToArray(request.param("index")));
recoveryRequest.detailed(request.paramAsBoolean("detailed", false));
recoveryRequest.activeOnly(request.paramAsBoolean("active_only", false));
recoveryRequest.indicesOptions(IndicesOptions.fromRequest(request, recoveryRequest.indicesOptions()));
return channel -> client.admin().indices().recoveries(recoveryRequest, new RestToXContentListener<>(channel));
}
use of org.opensearch.rest.action.RestToXContentListener in project OpenSearch by opensearch-project.
the class RestForceMergeAction method prepareRequest.
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
final ForceMergeRequest mergeRequest = new ForceMergeRequest(Strings.splitStringByCommaToArray(request.param("index")));
mergeRequest.indicesOptions(IndicesOptions.fromRequest(request, mergeRequest.indicesOptions()));
mergeRequest.maxNumSegments(request.paramAsInt("max_num_segments", mergeRequest.maxNumSegments()));
mergeRequest.onlyExpungeDeletes(request.paramAsBoolean("only_expunge_deletes", mergeRequest.onlyExpungeDeletes()));
mergeRequest.flush(request.paramAsBoolean("flush", mergeRequest.flush()));
if (mergeRequest.onlyExpungeDeletes() && mergeRequest.maxNumSegments() != ForceMergeRequest.Defaults.MAX_NUM_SEGMENTS) {
deprecationLogger.deprecate("force_merge_expunge_deletes_and_max_num_segments_deprecation", "setting only_expunge_deletes and max_num_segments at the same time is deprecated and will be rejected in a future version");
}
return channel -> client.admin().indices().forceMerge(mergeRequest, new RestToXContentListener<>(channel));
}
use of org.opensearch.rest.action.RestToXContentListener in project OpenSearch by opensearch-project.
the class RestGetIndexTemplateAction method prepareRequest.
@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
final String[] names = Strings.splitStringByCommaToArray(request.param("name"));
final GetIndexTemplatesRequest getIndexTemplatesRequest = new GetIndexTemplatesRequest(names);
getIndexTemplatesRequest.local(request.paramAsBoolean("local", getIndexTemplatesRequest.local()));
getIndexTemplatesRequest.masterNodeTimeout(request.paramAsTime("master_timeout", getIndexTemplatesRequest.masterNodeTimeout()));
final boolean implicitAll = getIndexTemplatesRequest.names().length == 0;
return channel -> client.admin().indices().getTemplates(getIndexTemplatesRequest, new RestToXContentListener<GetIndexTemplatesResponse>(channel) {
@Override
protected RestStatus getStatus(final GetIndexTemplatesResponse response) {
final boolean templateExists = response.getIndexTemplates().isEmpty() == false;
return (templateExists || implicitAll) ? OK : NOT_FOUND;
}
});
}
Aggregations