Search in sources :

Example 11 with ActionRequestValidationException

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

the class IndexRequestTests method testIndexingRejectsLongIds.

public void testIndexingRejectsLongIds() {
    String id = randomAsciiOfLength(511);
    IndexRequest request = new IndexRequest("index", "type", id);
    request.source("{}", XContentType.JSON);
    ActionRequestValidationException validate = request.validate();
    assertNull(validate);
    id = randomAsciiOfLength(512);
    request = new IndexRequest("index", "type", id);
    request.source("{}", XContentType.JSON);
    validate = request.validate();
    assertNull(validate);
    id = randomAsciiOfLength(513);
    request = new IndexRequest("index", "type", id);
    request.source("{}", XContentType.JSON);
    validate = request.validate();
    assertThat(validate, notNullValue());
    assertThat(validate.getMessage(), containsString("id is too long, must be no longer than 512 bytes but was: 513"));
}
Also used : ActionRequestValidationException(org.elasticsearch.action.ActionRequestValidationException) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 12 with ActionRequestValidationException

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

the class BulkRequestTests method testBulkRequestWithRefresh.

// issue 7361
public void testBulkRequestWithRefresh() throws Exception {
    BulkRequest bulkRequest = new BulkRequest();
    // We force here a "id is missing" validation error
    bulkRequest.add(new DeleteRequest("index", "type", null).setRefreshPolicy(RefreshPolicy.IMMEDIATE));
    // We force here a "type is missing" validation error
    bulkRequest.add(new DeleteRequest("index", null, "id"));
    bulkRequest.add(new DeleteRequest("index", "type", "id").setRefreshPolicy(RefreshPolicy.IMMEDIATE));
    bulkRequest.add(new UpdateRequest("index", "type", "id").doc("{}", XContentType.JSON).setRefreshPolicy(RefreshPolicy.IMMEDIATE));
    bulkRequest.add(new IndexRequest("index", "type", "id").source("{}", XContentType.JSON).setRefreshPolicy(RefreshPolicy.IMMEDIATE));
    ActionRequestValidationException validate = bulkRequest.validate();
    assertThat(validate, notNullValue());
    assertThat(validate.validationErrors(), not(empty()));
    assertThat(validate.validationErrors(), contains("RefreshPolicy is not supported on an item request. Set it on the BulkRequest instead.", "id is missing", "type is missing", "RefreshPolicy is not supported on an item request. Set it on the BulkRequest instead.", "RefreshPolicy is not supported on an item request. Set it on the BulkRequest instead.", "RefreshPolicy is not supported on an item request. Set it on the BulkRequest instead."));
}
Also used : ActionRequestValidationException(org.elasticsearch.action.ActionRequestValidationException) UpdateRequest(org.elasticsearch.action.update.UpdateRequest) IndexRequest(org.elasticsearch.action.index.IndexRequest) DeleteRequest(org.elasticsearch.action.delete.DeleteRequest)

Example 13 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 14 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 15 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