Search in sources :

Example 16 with ActionRequestValidationException

use of org.elasticsearch.action.ActionRequestValidationException in project elasticsearch by elastic.

the class AbstractBaseReindexRestHandler method doPrepareRequest.

protected RestChannelConsumer doPrepareRequest(RestRequest request, NodeClient client, boolean includeCreated, boolean includeUpdated) throws IOException {
    // Build the internal request
    Request internal = setCommonOptions(request, buildRequest(request));
    // Executes the request and waits for completion
    if (request.paramAsBoolean("wait_for_completion", true)) {
        Map<String, String> params = new HashMap<>();
        params.put(BulkByScrollTask.Status.INCLUDE_CREATED, Boolean.toString(includeCreated));
        params.put(BulkByScrollTask.Status.INCLUDE_UPDATED, Boolean.toString(includeUpdated));
        return channel -> client.executeLocally(action, internal, new BulkIndexByScrollResponseContentListener(channel, params));
    } else {
        internal.setShouldStoreResult(true);
    }
    /*
         * Let's try and validate before forking so the user gets some error. The
         * task can't totally validate until it starts but this is better than
         * nothing.
         */
    ActionRequestValidationException validationException = internal.validate();
    if (validationException != null) {
        throw validationException;
    }
    return sendTask(client.getLocalNodeId(), client.executeLocally(action, internal, LoggingTaskListener.instance()));
}
Also used : AbstractBulkByScrollRequest(org.elasticsearch.action.bulk.byscroll.AbstractBulkByScrollRequest) BaseRestHandler(org.elasticsearch.rest.BaseRestHandler) BulkByScrollResponse(org.elasticsearch.action.bulk.byscroll.BulkByScrollResponse) IOException(java.io.IOException) HashMap(java.util.HashMap) XContentBuilder(org.elasticsearch.common.xcontent.XContentBuilder) LoggingTaskListener(org.elasticsearch.tasks.LoggingTaskListener) ActiveShardCount(org.elasticsearch.action.support.ActiveShardCount) BytesRestResponse(org.elasticsearch.rest.BytesRestResponse) Settings(org.elasticsearch.common.settings.Settings) ActionRequestValidationException(org.elasticsearch.action.ActionRequestValidationException) RestStatus(org.elasticsearch.rest.RestStatus) Map(java.util.Map) RestRequest(org.elasticsearch.rest.RestRequest) NodeClient(org.elasticsearch.client.node.NodeClient) BulkByScrollTask(org.elasticsearch.action.bulk.byscroll.BulkByScrollTask) Task(org.elasticsearch.tasks.Task) GenericAction(org.elasticsearch.action.GenericAction) ActionRequestValidationException(org.elasticsearch.action.ActionRequestValidationException) HashMap(java.util.HashMap) AbstractBulkByScrollRequest(org.elasticsearch.action.bulk.byscroll.AbstractBulkByScrollRequest) RestRequest(org.elasticsearch.rest.RestRequest)

Example 17 with ActionRequestValidationException

use of org.elasticsearch.action.ActionRequestValidationException in project elasticsearch by elastic.

the class ReindexRequestTests method testReindexFromRemoteDoesNotSupportSearchQuery.

public void testReindexFromRemoteDoesNotSupportSearchQuery() {
    ReindexRequest reindex = newRequest();
    reindex.setRemoteInfo(new RemoteInfo(randomAsciiOfLength(5), randomAsciiOfLength(5), between(1, Integer.MAX_VALUE), new BytesArray("real_query"), null, null, emptyMap(), RemoteInfo.DEFAULT_SOCKET_TIMEOUT, RemoteInfo.DEFAULT_CONNECT_TIMEOUT));
    // Unsupported place to put query
    reindex.getSearchRequest().source().query(matchAllQuery());
    ActionRequestValidationException e = reindex.validate();
    assertEquals("Validation Failed: 1: reindex from remote sources should use RemoteInfo's query instead of source's query;", e.getMessage());
}
Also used : BytesArray(org.elasticsearch.common.bytes.BytesArray) ActionRequestValidationException(org.elasticsearch.action.ActionRequestValidationException) RemoteInfo(org.elasticsearch.index.reindex.remote.RemoteInfo)

Example 18 with ActionRequestValidationException

use of org.elasticsearch.action.ActionRequestValidationException in project elasticsearch by elastic.

the class ReindexRequestTests method testNoSliceWithWorkers.

public void testNoSliceWithWorkers() {
    ReindexRequest reindex = newRequest();
    reindex.getSearchRequest().source().slice(new SliceBuilder(0, 4));
    reindex.setSlices(between(2, Integer.MAX_VALUE));
    ActionRequestValidationException e = reindex.validate();
    assertEquals("Validation Failed: 1: can't specify both slice and workers;", e.getMessage());
}
Also used : SliceBuilder(org.elasticsearch.search.slice.SliceBuilder) ActionRequestValidationException(org.elasticsearch.action.ActionRequestValidationException)

Aggregations

ActionRequestValidationException (org.elasticsearch.action.ActionRequestValidationException)18 IOException (java.io.IOException)4 ActionRequest (org.elasticsearch.action.ActionRequest)4 IndexRequest (org.elasticsearch.action.index.IndexRequest)4 UpdateRequest (org.elasticsearch.action.update.UpdateRequest)4 DeleteRequest (org.elasticsearch.action.delete.DeleteRequest)3 GetRequest (org.elasticsearch.action.get.GetRequest)3 BytesRestResponse (org.elasticsearch.rest.BytesRestResponse)3 ElasticsearchException (org.elasticsearch.ElasticsearchException)2 ElasticsearchStatusException (org.elasticsearch.ElasticsearchStatusException)2 BulkRequest (org.elasticsearch.action.bulk.BulkRequest)2 GetResponse (org.elasticsearch.action.get.GetResponse)2 MainRequest (org.elasticsearch.action.main.MainRequest)2 NodeClient (org.elasticsearch.client.node.NodeClient)2 BytesArray (org.elasticsearch.common.bytes.BytesArray)2 Settings (org.elasticsearch.common.settings.Settings)2 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)2 RemoteInfo (org.elasticsearch.index.reindex.remote.RemoteInfo)2 BaseRestHandler (org.elasticsearch.rest.BaseRestHandler)2 RestRequest (org.elasticsearch.rest.RestRequest)2