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