use of org.elasticsearch.action.search.SearchRequest in project elasticsearch by elastic.
the class RestDeleteByQueryAction method buildRequest.
@Override
protected DeleteByQueryRequest buildRequest(RestRequest request) throws IOException {
if (false == request.hasContent()) {
throw new ElasticsearchException("_delete_by_query requires a request body");
}
/*
* Passing the search request through DeleteByQueryRequest first allows
* it to set its own defaults which differ from SearchRequest's
* defaults. Then the parseInternalRequest can override them.
*/
DeleteByQueryRequest internal = new DeleteByQueryRequest(new SearchRequest());
Map<String, Consumer<Object>> consumers = new HashMap<>();
consumers.put("conflicts", o -> internal.setConflicts((String) o));
parseInternalRequest(internal, request, consumers);
return internal;
}
use of org.elasticsearch.action.search.SearchRequest in project elasticsearch by elastic.
the class RestUpdateByQueryAction method buildRequest.
@Override
@SuppressWarnings("unchecked")
protected UpdateByQueryRequest buildRequest(RestRequest request) throws IOException {
/*
* Passing the search request through UpdateByQueryRequest first allows
* it to set its own defaults which differ from SearchRequest's
* defaults. Then the parse can override them.
*/
UpdateByQueryRequest internal = new UpdateByQueryRequest(new SearchRequest());
Map<String, Consumer<Object>> consumers = new HashMap<>();
consumers.put("conflicts", o -> internal.setConflicts((String) o));
consumers.put("script", o -> internal.setScript(parseScript((Map<String, Object>) o)));
parseInternalRequest(internal, request, consumers);
internal.setPipeline(request.param("pipeline"));
return internal;
}
use of org.elasticsearch.action.search.SearchRequest in project elasticsearch by elastic.
the class AbstractBulkByQueryRestHandler method parseInternalRequest.
protected void parseInternalRequest(Request internal, RestRequest restRequest, Map<String, Consumer<Object>> bodyConsumers) throws IOException {
assert internal != null : "Request should not be null";
assert restRequest != null : "RestRequest should not be null";
SearchRequest searchRequest = internal.getSearchRequest();
int scrollSize = searchRequest.source().size();
searchRequest.source().size(SIZE_ALL_MATCHES);
restRequest.withContentOrSourceParamParserOrNull(parser -> {
XContentParser searchRequestParser = extractRequestSpecificFieldsAndReturnSearchCompatibleParser(parser, bodyConsumers);
try {
RestSearchAction.parseSearchRequest(searchRequest, restRequest, searchRequestParser);
} finally {
IOUtils.close(searchRequestParser);
}
});
internal.setSize(searchRequest.source().size());
searchRequest.source().size(restRequest.paramAsInt("scroll_size", scrollSize));
String conflicts = restRequest.param("conflicts");
if (conflicts != null) {
internal.setConflicts(conflicts);
}
// Let the requester set search timeout. It is probably only going to be useful for testing but who knows.
if (restRequest.hasParam("search_timeout")) {
searchRequest.source().timeout(restRequest.paramAsTime("search_timeout", null));
}
}
use of org.elasticsearch.action.search.SearchRequest in project elasticsearch by elastic.
the class RoundTripTests method testUpdateByQueryRequest.
public void testUpdateByQueryRequest() throws IOException {
UpdateByQueryRequest update = new UpdateByQueryRequest(new SearchRequest());
randomRequest(update);
if (randomBoolean()) {
update.setPipeline(randomAsciiOfLength(5));
}
UpdateByQueryRequest tripped = new UpdateByQueryRequest();
roundTrip(update, tripped);
assertRequestEquals(update, tripped);
assertEquals(update.getPipeline(), tripped.getPipeline());
// Try slices with a version that doesn't support slices. That should fail.
update.setSlices(between(2, 1000));
Exception e = expectThrows(IllegalArgumentException.class, () -> roundTrip(Version.V_5_0_0_rc1, update, null));
assertEquals("Attempting to send sliced reindex-style request to a node that doesn't support it. " + "Version is [5.0.0-rc1] but must be [5.1.1]", e.getMessage());
// Try without slices with a version that doesn't support slices. That should work.
tripped = new UpdateByQueryRequest();
update.setSlices(1);
roundTrip(Version.V_5_0_0_rc1, update, tripped);
assertRequestEquals(update, tripped);
assertEquals(update.getPipeline(), tripped.getPipeline());
}
use of org.elasticsearch.action.search.SearchRequest in project elasticsearch by elastic.
the class UpdateByQueryRequestTests method testUpdateByQueryRequestImplementsIndicesRequestReplaceable.
public void testUpdateByQueryRequestImplementsIndicesRequestReplaceable() {
int numIndices = between(1, 100);
String[] indices = new String[numIndices];
for (int i = 0; i < numIndices; i++) {
indices[i] = randomSimpleString(random(), 1, 30);
}
SearchRequest searchRequest = new SearchRequest(indices);
IndicesOptions indicesOptions = IndicesOptions.fromOptions(randomBoolean(), randomBoolean(), randomBoolean(), randomBoolean());
searchRequest.indicesOptions(indicesOptions);
UpdateByQueryRequest request = new UpdateByQueryRequest(searchRequest);
for (int i = 0; i < numIndices; i++) {
assertEquals(indices[i], request.indices()[i]);
}
assertSame(indicesOptions, request.indicesOptions());
assertSame(request.indicesOptions(), request.getSearchRequest().indicesOptions());
int numNewIndices = between(1, 100);
String[] newIndices = new String[numNewIndices];
for (int i = 0; i < numNewIndices; i++) {
newIndices[i] = randomSimpleString(random(), 1, 30);
}
request.indices(newIndices);
for (int i = 0; i < numNewIndices; i++) {
;
assertEquals(newIndices[i], request.indices()[i]);
}
for (int i = 0; i < numNewIndices; i++) {
;
assertEquals(newIndices[i], request.getSearchRequest().indices()[i]);
}
}
Aggregations