use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchResponse in project graylog2-server by Graylog2.
the class ElasticsearchBackendMultiSearchTest method multiSearchResultsAreAssignedToSearchTypes.
@Test
public void multiSearchResultsAreAssignedToSearchTypes() throws Exception {
final MultiSearchResponse response = TestMultisearchResponse.fromFixture("successfulMultiSearchResponse.json");
final List<MultiSearchResponse.Item> items = Arrays.stream(response.getResponses()).collect(Collectors.toList());
when(client.msearch(any(), any())).thenReturn(items);
final ESGeneratedQueryContext queryContext = this.elasticsearchBackend.generate(searchJob, query, new SearchConfig(Period.ZERO));
final QueryResult queryResult = this.elasticsearchBackend.doRun(searchJob, query, queryContext);
assertThat(queryResult.searchTypes()).containsOnlyKeys("pivot1", "pivot2");
final PivotResult pivot1Result = (PivotResult) queryResult.searchTypes().get("pivot1");
assertThat(pivot1Result.rows().get(0)).isEqualTo(PivotResult.Row.builder().key(ImmutableList.of()).source("leaf").addValue(PivotResult.Value.create(Collections.singletonList("avg(field1)"), 27220.273504273504, true, "row-leaf")).build());
final PivotResult pivot2Result = (PivotResult) queryResult.searchTypes().get("pivot2");
assertThat(pivot2Result.rows().get(0)).isEqualTo(PivotResult.Row.builder().key(ImmutableList.of()).source("leaf").addValue(PivotResult.Value.create(Collections.singletonList("max(field2)"), 42.0, true, "row-leaf")).build());
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchResponse in project graylog2-server by Graylog2.
the class ElasticsearchClient method msearch.
public List<MultiSearchResponse.Item> msearch(List<SearchRequest> searchRequests, String errorMessage) {
final MultiSearchRequest multiSearchRequest = new MultiSearchRequest();
searchRequests.forEach(multiSearchRequest::add);
final MultiSearchResponse result = this.execute((c, requestOptions) -> c.msearch(multiSearchRequest, requestOptions), errorMessage);
return Streams.stream(result).collect(Collectors.toList());
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchResponse in project graylog2-server by Graylog2.
the class ElasticsearchClient method search.
public SearchResponse search(SearchRequest searchRequest, String errorMessage) {
final MultiSearchRequest multiSearchRequest = new MultiSearchRequest().add(searchRequest);
final MultiSearchResponse result = this.execute((c, requestOptions) -> c.msearch(multiSearchRequest, requestOptions), errorMessage);
return firstResponseFrom(result, errorMessage);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchResponse in project graylog2-server by Graylog2.
the class ElasticsearchBackend method checkForFailedShards.
private Optional<ElasticsearchException> checkForFailedShards(MultiSearchResponse.Item multiSearchResponse) {
if (multiSearchResponse.isFailure()) {
return Optional.of(new ElasticsearchException(multiSearchResponse.getFailureMessage(), multiSearchResponse.getFailure()));
}
final SearchResponse searchResponse = multiSearchResponse.getResponse();
if (searchResponse != null && searchResponse.getFailedShards() > 0) {
final List<Throwable> shardFailures = Arrays.stream(searchResponse.getShardFailures()).map(ShardOperationFailedException::getCause).collect(Collectors.toList());
final List<String> nonNumericFieldErrors = shardFailures.stream().filter(shardFailure -> shardFailure.getMessage().contains("Expected numeric type on field")).map(Throwable::getMessage).distinct().collect(Collectors.toList());
if (!nonNumericFieldErrors.isEmpty()) {
return Optional.of(new FieldTypeException("Unable to perform search query: ", nonNumericFieldErrors));
}
final List<String> errors = shardFailures.stream().map(Throwable::getMessage).distinct().collect(Collectors.toList());
return Optional.of(new ElasticsearchException("Unable to perform search query: ", errors));
}
return Optional.empty();
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchResponse in project elasticsearch by elastic.
the class MultiSearchIT method testSimpleMultiSearchMoreRequests.
public void testSimpleMultiSearchMoreRequests() {
createIndex("test");
int numDocs = randomIntBetween(0, 16);
for (int i = 0; i < numDocs; i++) {
client().prepareIndex("test", "type", Integer.toString(i)).setSource("{}", XContentType.JSON).get();
}
refresh();
int numSearchRequests = randomIntBetween(1, 64);
MultiSearchRequest request = new MultiSearchRequest();
if (randomBoolean()) {
request.maxConcurrentSearchRequests(randomIntBetween(1, numSearchRequests));
}
for (int i = 0; i < numSearchRequests; i++) {
request.add(client().prepareSearch("test"));
}
MultiSearchResponse response = client().multiSearch(request).actionGet();
assertThat(response.getResponses().length, equalTo(numSearchRequests));
for (MultiSearchResponse.Item item : response) {
assertNoFailures(item.getResponse());
assertHitCount(item.getResponse(), numDocs);
}
}
Aggregations