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"));
}
}
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;
}
}
}
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());
}
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];"));
}
}
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());
}
}
Aggregations