Search in sources :

Example 6 with MultiSearchResponse

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());
}
Also used : MultiSearchResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchResponse) QueryResult(org.graylog.plugins.views.search.QueryResult) PivotResult(org.graylog.plugins.views.search.searchtypes.pivot.PivotResult) SearchConfig(org.graylog.plugins.views.search.engine.SearchConfig) Test(org.junit.Test)

Example 7 with MultiSearchResponse

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());
}
Also used : MultiSearchResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchResponse) MultiSearchRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchRequest)

Example 8 with MultiSearchResponse

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);
}
Also used : MultiSearchResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchResponse) MultiSearchRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchRequest)

Example 9 with MultiSearchResponse

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();
}
Also used : ESSearchTypeHandler(org.graylog.storage.elasticsearch7.views.searchtypes.ESSearchTypeHandler) AndFilter(org.graylog.plugins.views.search.filter.AndFilter) ElasticsearchClient(org.graylog.storage.elasticsearch7.ElasticsearchClient) Arrays(java.util.Arrays) BackendQuery(org.graylog.plugins.views.search.engine.BackendQuery) QueryBackend(org.graylog.plugins.views.search.engine.QueryBackend) Provider(javax.inject.Provider) LoggerFactory(org.slf4j.LoggerFactory) FieldTypeException(org.graylog2.indexer.FieldTypeException) MultiSearchResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchResponse) StreamFilter(org.graylog.plugins.views.search.filter.StreamFilter) Map(java.util.Map) IndicesOptions(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.support.IndicesOptions) SearchConfig(org.graylog.plugins.views.search.engine.SearchConfig) Set(java.util.Set) Collectors(java.util.stream.Collectors) BoolQueryBuilder(org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.BoolQueryBuilder) Objects(java.util.Objects) List(java.util.List) Filter(org.graylog.plugins.views.search.Filter) Optional(java.util.Optional) SearchResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchResponse) Query(org.graylog.plugins.views.search.Query) SearchTypeErrorParser(org.graylog.plugins.views.search.errors.SearchTypeErrorParser) HashMap(java.util.HashMap) ElasticsearchException(org.graylog2.indexer.ElasticsearchException) ShardOperationFailedException(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.ShardOperationFailedException) ArrayList(java.util.ArrayList) GlobalOverride(org.graylog.plugins.views.search.GlobalOverride) Inject(javax.inject.Inject) HashSet(java.util.HashSet) OrFilter(org.graylog.plugins.views.search.filter.OrFilter) SearchType(org.graylog.plugins.views.search.SearchType) QueryStringFilter(org.graylog.plugins.views.search.filter.QueryStringFilter) SearchTypeError(org.graylog.plugins.views.search.errors.SearchTypeError) QueryResult(org.graylog.plugins.views.search.QueryResult) TimeRangeQueryFactory(org.graylog.storage.elasticsearch7.TimeRangeQueryFactory) SearchJob(org.graylog.plugins.views.search.SearchJob) QueryBuilder(org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.QueryBuilder) SearchSourceBuilder(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.builder.SearchSourceBuilder) Logger(org.slf4j.Logger) SearchRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest) Maps(com.google.common.collect.Maps) QueryStringDecorators(org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators) Named(com.google.inject.name.Named) IndexLookup(org.graylog.plugins.views.search.elasticsearch.IndexLookup) QueryBuilders(org.graylog.shaded.elasticsearch7.org.elasticsearch.index.query.QueryBuilders) Message(org.graylog2.plugin.Message) Collections(java.util.Collections) FieldTypeException(org.graylog2.indexer.FieldTypeException) ElasticsearchException(org.graylog2.indexer.ElasticsearchException) MultiSearchResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchResponse) SearchResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchResponse)

Example 10 with MultiSearchResponse

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);
    }
}
Also used : MultiSearchResponse(org.elasticsearch.action.search.MultiSearchResponse) MultiSearchRequest(org.elasticsearch.action.search.MultiSearchRequest)

Aggregations

MultiSearchResponse (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchResponse)13 Test (org.junit.Test)10 MultiSearchResponse (org.elasticsearch.action.search.MultiSearchResponse)8 SearchConfig (org.graylog.plugins.views.search.engine.SearchConfig)8 QueryResult (org.graylog.plugins.views.search.QueryResult)6 SearchRequest (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)4 Arrays (java.util.Arrays)3 List (java.util.List)3 Map (java.util.Map)3 Collectors (java.util.stream.Collectors)3 Provider (javax.inject.Provider)3 SearchRequestBuilder (org.elasticsearch.action.search.SearchRequestBuilder)3 Query (org.graylog.plugins.views.search.Query)3 SearchJob (org.graylog.plugins.views.search.SearchJob)3 SearchType (org.graylog.plugins.views.search.SearchType)3 IndexLookup (org.graylog.plugins.views.search.elasticsearch.IndexLookup)3 QueryStringDecorators (org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators)3 SearchTypeError (org.graylog.plugins.views.search.errors.SearchTypeError)3