Search in sources :

Example 6 with RestStatusToXContentListener

use of org.elasticsearch.rest.action.RestStatusToXContentListener in project elasticsearch by elastic.

the class RestGetPipelineAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(RestRequest restRequest, NodeClient client) throws IOException {
    GetPipelineRequest request = new GetPipelineRequest(Strings.splitStringByCommaToArray(restRequest.param("id")));
    request.masterNodeTimeout(restRequest.paramAsTime("master_timeout", request.masterNodeTimeout()));
    return channel -> client.admin().cluster().getPipeline(request, new RestStatusToXContentListener<>(channel));
}
Also used : BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) Settings(org.elasticsearch.common.settings.Settings) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) RestStatusToXContentListener(org.elasticsearch.rest.action.RestStatusToXContentListener) IOException(java.io.IOException) GetPipelineRequest(org.elasticsearch.action.ingest.GetPipelineRequest) RestController(org.elasticsearch.rest.RestController) Strings(org.elasticsearch.common.Strings) GetPipelineRequest(org.elasticsearch.action.ingest.GetPipelineRequest)

Example 7 with RestStatusToXContentListener

use of org.elasticsearch.rest.action.RestStatusToXContentListener in project elasticsearch by elastic.

the class RestClearScrollAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    String scrollIds = request.param("scroll_id");
    ClearScrollRequest clearRequest = new ClearScrollRequest();
    clearRequest.setScrollIds(Arrays.asList(splitScrollIds(scrollIds)));
    request.withContentOrSourceParamParserOrNull((xContentParser -> {
        if (xContentParser != null) {
            clearRequest.setScrollIds(null);
            try {
                buildFromContent(xContentParser, clearRequest);
            } catch (IOException e) {
                throw new IllegalArgumentException("Failed to parse request body", e);
            }
        }
    }));
    return channel -> client.clearScroll(clearRequest, new RestStatusToXContentListener<>(channel));
}
Also used : XContentParser(org.elasticsearch.common.xcontent.XContentParser) BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) Arrays(java.util.Arrays) Settings(org.elasticsearch.common.settings.Settings) DELETE(org.elasticsearch.rest.RestRequest.Method.DELETE) ClearScrollRequest(org.elasticsearch.action.search.ClearScrollRequest) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) RestStatusToXContentListener(org.elasticsearch.rest.action.RestStatusToXContentListener) IOException(java.io.IOException) RestController(org.elasticsearch.rest.RestController) Strings(org.elasticsearch.common.Strings) ClearScrollRequest(org.elasticsearch.action.search.ClearScrollRequest) IOException(java.io.IOException)

Example 8 with RestStatusToXContentListener

use of org.elasticsearch.rest.action.RestStatusToXContentListener in project elasticsearch by elastic.

the class RestBulkAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    BulkRequest bulkRequest = Requests.bulkRequest();
    String defaultIndex = request.param("index");
    String defaultType = request.param("type");
    String defaultRouting = request.param("routing");
    FetchSourceContext defaultFetchSourceContext = FetchSourceContext.parseFromRestRequest(request);
    String fieldsParam = request.param("fields");
    if (fieldsParam != null) {
        DEPRECATION_LOGGER.deprecated("Deprecated field [fields] used, expected [_source] instead");
    }
    String[] defaultFields = fieldsParam != null ? Strings.commaDelimitedListToStringArray(fieldsParam) : null;
    String defaultPipeline = request.param("pipeline");
    String waitForActiveShards = request.param("wait_for_active_shards");
    if (waitForActiveShards != null) {
        bulkRequest.waitForActiveShards(ActiveShardCount.parseString(waitForActiveShards));
    }
    bulkRequest.timeout(request.paramAsTime("timeout", BulkShardRequest.DEFAULT_TIMEOUT));
    bulkRequest.setRefreshPolicy(request.param("refresh"));
    bulkRequest.add(request.content(), defaultIndex, defaultType, defaultRouting, defaultFields, defaultFetchSourceContext, defaultPipeline, null, allowExplicitIndex, request.getXContentType());
    return channel -> client.bulk(bulkRequest, new RestStatusToXContentListener<>(channel));
}
Also used : Loggers(org.elasticsearch.common.logging.Loggers) BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) DeprecationLogger(org.elasticsearch.common.logging.DeprecationLogger) RestStatusToXContentListener(org.elasticsearch.rest.action.RestStatusToXContentListener) IOException(java.io.IOException) RestController(org.elasticsearch.rest.RestController) PUT(org.elasticsearch.rest.RestRequest.Method.PUT) Strings(org.elasticsearch.common.Strings) ActiveShardCount(org.elasticsearch.action.support.ActiveShardCount) POST(org.elasticsearch.rest.RestRequest.Method.POST) Settings(org.elasticsearch.common.settings.Settings) BulkShardRequest(org.elasticsearch.action.bulk.BulkShardRequest) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) Requests(org.elasticsearch.client.Requests) BulkRequest(org.elasticsearch.action.bulk.BulkRequest) FetchSourceContext(org.elasticsearch.search.fetch.subphase.FetchSourceContext) FetchSourceContext(org.elasticsearch.search.fetch.subphase.FetchSourceContext) BulkRequest(org.elasticsearch.action.bulk.BulkRequest)

Example 9 with RestStatusToXContentListener

use of org.elasticsearch.rest.action.RestStatusToXContentListener in project elasticsearch by elastic.

the class RestDeleteAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client) throws IOException {
    DeleteRequest deleteRequest = new DeleteRequest(request.param("index"), request.param("type"), request.param("id"));
    deleteRequest.routing(request.param("routing"));
    deleteRequest.parent(request.param("parent"));
    deleteRequest.timeout(request.paramAsTime("timeout", DeleteRequest.DEFAULT_TIMEOUT));
    deleteRequest.setRefreshPolicy(request.param("refresh"));
    deleteRequest.version(RestActions.parseVersion(request));
    deleteRequest.versionType(VersionType.fromString(request.param("version_type"), deleteRequest.versionType()));
    String waitForActiveShards = request.param("wait_for_active_shards");
    if (waitForActiveShards != null) {
        deleteRequest.waitForActiveShards(ActiveShardCount.parseString(waitForActiveShards));
    }
    return channel -> client.delete(deleteRequest, new RestStatusToXContentListener<>(channel));
}
Also used : ActiveShardCount(org.elasticsearch.action.support.ActiveShardCount) BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) DeleteRequest(org.elasticsearch.action.delete.DeleteRequest) Settings(org.elasticsearch.common.settings.Settings) DELETE(org.elasticsearch.rest.RestRequest.Method.DELETE) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) RestStatusToXContentListener(org.elasticsearch.rest.action.RestStatusToXContentListener) IOException(java.io.IOException) RestController(org.elasticsearch.rest.RestController) VersionType(org.elasticsearch.index.VersionType) RestActions(org.elasticsearch.rest.action.RestActions) DeleteRequest(org.elasticsearch.action.delete.DeleteRequest)

Example 10 with RestStatusToXContentListener

use of org.elasticsearch.rest.action.RestStatusToXContentListener in project elasticsearch by elastic.

the class RestSearchTemplateAction method prepareRequest.

@Override
public RestChannelConsumer prepareRequest(RestRequest request, NodeClient client) throws IOException {
    if (request.hasContentOrSourceParam() == false) {
        throw new ElasticsearchException("request body is required");
    }
    // Creates the search request with all required params
    SearchRequest searchRequest = new SearchRequest();
    RestSearchAction.parseSearchRequest(searchRequest, request, null);
    // Creates the search template request
    SearchTemplateRequest searchTemplateRequest;
    try (XContentParser parser = request.contentOrSourceParamParser()) {
        searchTemplateRequest = PARSER.parse(parser, new SearchTemplateRequest(), null);
    }
    searchTemplateRequest.setRequest(searchRequest);
    return channel -> client.execute(SearchTemplateAction.INSTANCE, searchTemplateRequest, new RestStatusToXContentListener<>(channel));
}
Also used : ElasticsearchException(org.elasticsearch.ElasticsearchException) BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) XContentFactory(org.elasticsearch.common.xcontent.XContentFactory) GET(org.elasticsearch.rest.RestRequest.Method.GET) ParsingException(org.elasticsearch.common.ParsingException) RestSearchAction(org.elasticsearch.rest.action.search.RestSearchAction) ScriptType(org.elasticsearch.script.ScriptType) RestStatusToXContentListener(org.elasticsearch.rest.action.RestStatusToXContentListener) Set(java.util.Set) IOException(java.io.IOException) SearchRequest(org.elasticsearch.action.search.SearchRequest) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) RestController(org.elasticsearch.rest.RestController) XContentParser(org.elasticsearch.common.xcontent.XContentParser) POST(org.elasticsearch.rest.RestRequest.Method.POST) Settings(org.elasticsearch.common.settings.Settings) ObjectParser(org.elasticsearch.common.xcontent.ObjectParser) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) ParseField(org.elasticsearch.common.ParseField) Collections(java.util.Collections) SearchRequest(org.elasticsearch.action.search.SearchRequest) ElasticsearchException(org.elasticsearch.ElasticsearchException) XContentParser(org.elasticsearch.common.xcontent.XContentParser)

Aggregations

IOException (java.io.IOException)10 NodeClient (org.elasticsearch.client.node.NodeClient)10 Settings (org.elasticsearch.common.settings.Settings)10 BaseRestHandler (org.elasticsearch.rest.BaseRestHandler)10 RestController (org.elasticsearch.rest.RestController)10 RestRequest (org.elasticsearch.rest.RestRequest)10 RestStatusToXContentListener (org.elasticsearch.rest.action.RestStatusToXContentListener)10 Strings (org.elasticsearch.common.Strings)6 POST (org.elasticsearch.rest.RestRequest.Method.POST)6 ActiveShardCount (org.elasticsearch.action.support.ActiveShardCount)5 XContentParser (org.elasticsearch.common.xcontent.XContentParser)4 RestActions (org.elasticsearch.rest.action.RestActions)4 Collections (java.util.Collections)3 Set (java.util.Set)3 VersionType (org.elasticsearch.index.VersionType)3 GET (org.elasticsearch.rest.RestRequest.Method.GET)3 FetchSourceContext (org.elasticsearch.search.fetch.subphase.FetchSourceContext)3 Arrays (java.util.Arrays)2 IndexRequest (org.elasticsearch.action.index.IndexRequest)2 SearchRequest (org.elasticsearch.action.search.SearchRequest)2