use of org.graylog.shaded.elasticsearch7.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.graylog.shaded.elasticsearch7.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.graylog.shaded.elasticsearch7.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]);
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest in project elasticsearch by elastic.
the class RemoteRequestBuildersTests method testInitialSearchParamsSort.
public void testInitialSearchParamsSort() {
SearchRequest searchRequest = new SearchRequest().source(new SearchSourceBuilder());
// Test sort:_doc for versions that support it.
Version remoteVersion = Version.fromId(between(Version.V_2_1_0_ID, Version.CURRENT.id));
searchRequest.source().sort("_doc");
assertThat(initialSearchParams(searchRequest, remoteVersion), hasEntry("sort", "_doc:asc"));
// Test search_type scan for versions that don't support sort:_doc.
remoteVersion = Version.fromId(between(0, Version.V_2_1_0_ID - 1));
assertThat(initialSearchParams(searchRequest, remoteVersion), hasEntry("search_type", "scan"));
// Test sorting by some field. Version doesn't matter.
remoteVersion = Version.fromId(between(0, Version.CURRENT.id));
searchRequest.source().sorts().clear();
searchRequest.source().sort("foo");
assertThat(initialSearchParams(searchRequest, remoteVersion), hasEntry("sort", "foo:asc"));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest in project elasticsearch by elastic.
the class RemoteRequestBuildersTests method testInitialSearchEntity.
public void testInitialSearchEntity() throws IOException {
SearchRequest searchRequest = new SearchRequest();
searchRequest.source(new SearchSourceBuilder());
String query = "{\"match_all\":{}}";
HttpEntity entity = initialSearchEntity(searchRequest, new BytesArray(query));
assertEquals(ContentType.APPLICATION_JSON.toString(), entity.getContentType().getValue());
assertEquals("{\"query\":" + query + ",\"_source\":true}", Streams.copyToString(new InputStreamReader(entity.getContent(), StandardCharsets.UTF_8)));
// Source filtering is included if set up
searchRequest.source().fetchSource(new String[] { "in1", "in2" }, new String[] { "out" });
entity = initialSearchEntity(searchRequest, new BytesArray(query));
assertEquals(ContentType.APPLICATION_JSON.toString(), entity.getContentType().getValue());
assertEquals("{\"query\":" + query + ",\"_source\":{\"includes\":[\"in1\",\"in2\"],\"excludes\":[\"out\"]}}", Streams.copyToString(new InputStreamReader(entity.getContent(), StandardCharsets.UTF_8)));
// Invalid XContent fails
RuntimeException e = expectThrows(RuntimeException.class, () -> initialSearchEntity(searchRequest, new BytesArray("{}, \"trailing\": {}")));
assertThat(e.getCause().getMessage(), containsString("Unexpected character (',' (code 44))"));
e = expectThrows(RuntimeException.class, () -> initialSearchEntity(searchRequest, new BytesArray("{")));
assertThat(e.getCause().getMessage(), containsString("Unexpected end-of-input"));
}
Aggregations