Search in sources :

Example 1 with ActionRequestValidationException

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

the class UpdateIT method testUpdateRequestWithBothScriptAndDoc.

public void testUpdateRequestWithBothScriptAndDoc() throws Exception {
    createTestIndex();
    ensureGreen();
    try {
        client().prepareUpdate(indexOrAlias(), "type1", "1").setDoc(XContentFactory.jsonBuilder().startObject().field("field", 1).endObject()).setScript(new Script(ScriptType.INLINE, "field_inc", "field", Collections.emptyMap())).execute().actionGet();
        fail("Should have thrown ActionRequestValidationException");
    } catch (ActionRequestValidationException e) {
        assertThat(e.validationErrors().size(), equalTo(1));
        assertThat(e.validationErrors().get(0), containsString("can't provide both script and doc"));
        assertThat(e.getMessage(), containsString("can't provide both script and doc"));
    }
}
Also used : SearchScript(org.elasticsearch.script.SearchScript) Script(org.elasticsearch.script.Script) CompiledScript(org.elasticsearch.script.CompiledScript) ExecutableScript(org.elasticsearch.script.ExecutableScript) ActionRequestValidationException(org.elasticsearch.action.ActionRequestValidationException)

Example 2 with ActionRequestValidationException

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

the class TransportReindexAction method validateAgainstAliases.

/**
     * Throws an ActionRequestValidationException if the request tries to index
     * back into the same index or into an index that points to two indexes.
     * This cannot be done during request validation because the cluster state
     * isn't available then. Package private for testing.
     */
static void validateAgainstAliases(SearchRequest source, IndexRequest destination, RemoteInfo remoteInfo, IndexNameExpressionResolver indexNameExpressionResolver, AutoCreateIndex autoCreateIndex, ClusterState clusterState) {
    if (remoteInfo != null) {
        return;
    }
    String target = destination.index();
    if (false == autoCreateIndex.shouldAutoCreate(target, clusterState)) {
        /*
             * If we're going to autocreate the index we don't need to resolve
             * it. This is the same sort of dance that TransportIndexRequest
             * uses to decide to autocreate the index.
             */
        target = indexNameExpressionResolver.concreteIndexNames(clusterState, destination)[0];
    }
    for (String sourceIndex : indexNameExpressionResolver.concreteIndexNames(clusterState, source)) {
        if (sourceIndex.equals(target)) {
            ActionRequestValidationException e = new ActionRequestValidationException();
            e.addValidationError("reindex cannot write into an index its reading from [" + target + ']');
            throw e;
        }
    }
}
Also used : ActionRequestValidationException(org.elasticsearch.action.ActionRequestValidationException)

Example 3 with ActionRequestValidationException

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

the class ReindexRequestTests method testReindexFromRemoteDoesNotSupportWorkers.

public void testReindexFromRemoteDoesNotSupportWorkers() {
    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));
    reindex.setSlices(between(2, Integer.MAX_VALUE));
    ActionRequestValidationException e = reindex.validate();
    assertEquals("Validation Failed: 1: reindex from remote sources doesn't support workers > 1 but was [" + reindex.getSlices() + "];", e.getMessage());
}
Also used : BytesArray(org.elasticsearch.common.bytes.BytesArray) ActionRequestValidationException(org.elasticsearch.action.ActionRequestValidationException) RemoteInfo(org.elasticsearch.index.reindex.remote.RemoteInfo)

Example 4 with ActionRequestValidationException

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

the class FieldStatsIntegrationIT method testFieldStatsIndexLevel.

public void testFieldStatsIndexLevel() throws Exception {
    assertAcked(prepareCreate("test1").addMapping("test", "value", "type=long"));
    assertAcked(prepareCreate("test2").addMapping("test", "value", "type=long"));
    assertAcked(prepareCreate("test3").addMapping("test", "value", "type=long"));
    ensureGreen("test1", "test2", "test3");
    indexRange("test1", -10, 100);
    indexRange("test2", 101, 200);
    indexRange("test3", 201, 300);
    // default:
    FieldStatsResponse response = client().prepareFieldStats().setFields("value").get();
    assertAllSuccessful(response);
    assertThat(response.getAllFieldStats().get("value").getMinValue(), equalTo(-10L));
    assertThat(response.getAllFieldStats().get("value").getMaxValue(), equalTo(300L));
    assertThat(response.getIndicesMergedFieldStats().size(), equalTo(1));
    assertThat(response.getIndicesMergedFieldStats().get("_all").get("value").getMinValue(), equalTo(-10L));
    assertThat(response.getIndicesMergedFieldStats().get("_all").get("value").getMaxValue(), equalTo(300L));
    assertThat(response.getIndicesMergedFieldStats().get("_all").get("value").getDisplayType(), equalTo("integer"));
    // Level: cluster
    response = client().prepareFieldStats().setFields("value").setLevel("cluster").get();
    assertAllSuccessful(response);
    assertThat(response.getAllFieldStats().get("value").getMinValue(), equalTo(-10L));
    assertThat(response.getAllFieldStats().get("value").getMaxValue(), equalTo(300L));
    assertThat(response.getIndicesMergedFieldStats().size(), equalTo(1));
    assertThat(response.getIndicesMergedFieldStats().get("_all").get("value").getMinValue(), equalTo(-10L));
    assertThat(response.getIndicesMergedFieldStats().get("_all").get("value").getMaxValue(), equalTo(300L));
    assertThat(response.getIndicesMergedFieldStats().get("_all").get("value").getDisplayType(), equalTo("integer"));
    // Level: indices
    response = client().prepareFieldStats().setFields("value").setLevel("indices").get();
    assertAllSuccessful(response);
    assertThat(response.getAllFieldStats(), nullValue());
    assertThat(response.getIndicesMergedFieldStats().size(), equalTo(3));
    assertThat(response.getIndicesMergedFieldStats().get("test1").get("value").getMinValue(), equalTo(-10L));
    assertThat(response.getIndicesMergedFieldStats().get("test1").get("value").getMaxValue(), equalTo(100L));
    assertThat(response.getIndicesMergedFieldStats().get("test2").get("value").getMinValue(), equalTo(101L));
    assertThat(response.getIndicesMergedFieldStats().get("test2").get("value").getMaxValue(), equalTo(200L));
    assertThat(response.getIndicesMergedFieldStats().get("test3").get("value").getMinValue(), equalTo(201L));
    assertThat(response.getIndicesMergedFieldStats().get("test3").get("value").getMaxValue(), equalTo(300L));
    assertThat(response.getIndicesMergedFieldStats().get("test3").get("value").getDisplayType(), equalTo("integer"));
    // Illegal level option:
    try {
        client().prepareFieldStats().setFields("value").setLevel("illegal").get();
        fail();
    } catch (ActionRequestValidationException e) {
        assertThat(e.getMessage(), equalTo("Validation Failed: 1: invalid level option [illegal];"));
    }
}
Also used : ActionRequestValidationException(org.elasticsearch.action.ActionRequestValidationException) FieldStatsResponse(org.elasticsearch.action.fieldstats.FieldStatsResponse)

Example 5 with ActionRequestValidationException

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

the class RestHighLevelClientTests method testRequestValidation.

public void testRequestValidation() {
    ActionRequestValidationException validationException = new ActionRequestValidationException();
    validationException.addValidationError("validation error");
    ActionRequest request = new ActionRequest() {

        @Override
        public ActionRequestValidationException validate() {
            return validationException;
        }
    };
    {
        ActionRequestValidationException actualException = expectThrows(ActionRequestValidationException.class, () -> restHighLevelClient.performRequest(request, null, null, null));
        assertSame(validationException, actualException);
    }
    {
        TrackingActionListener trackingActionListener = new TrackingActionListener();
        restHighLevelClient.performRequestAsync(request, null, null, trackingActionListener, null);
        assertSame(validationException, trackingActionListener.exception.get());
    }
}
Also used : ActionRequestValidationException(org.elasticsearch.action.ActionRequestValidationException) ActionRequest(org.elasticsearch.action.ActionRequest)

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