Search in sources :

Example 1 with QueryResult

use of org.graylog.plugins.views.search.QueryResult in project graylog2-server by Graylog2.

the class ElasticsearchBackendErrorHandlingTest method deduplicateShardErrorsOnSearchTypeLevel.

@Test
public void deduplicateShardErrorsOnSearchTypeLevel() throws IOException {
    final MultiSearchResponse multiSearchResult = TestMultisearchResponse.fromFixture("errorhandling/failureOnSearchTypeLevel.json");
    final List<MultiSearchResponse.Item> items = Arrays.stream(multiSearchResult.getResponses()).collect(Collectors.toList());
    when(client.msearch(any(), any())).thenReturn(items);
    final QueryResult queryResult = this.backend.doRun(searchJob, query, queryContext);
    final Set<SearchError> errors = queryResult.errors();
    assertThat(errors).isNotNull();
    assertThat(errors).hasSize(1);
    assertThat(errors.stream().map(SearchError::description).collect(Collectors.toList())).containsExactly("Unable to perform search query: " + "\n\nElasticsearch exception [type=query_shard_exception, reason=Failed to parse query [[]].");
}
Also used : MultiSearchResponse(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchResponse) QueryResult(org.graylog.plugins.views.search.QueryResult) SearchError(org.graylog.plugins.views.search.errors.SearchError) Test(org.junit.Test)

Example 2 with QueryResult

use of org.graylog.plugins.views.search.QueryResult 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 3 with QueryResult

use of org.graylog.plugins.views.search.QueryResult in project graylog2-server by Graylog2.

the class ElasticsearchBackendTest method executesSearchForEmptySearchTypes.

@Test
public void executesSearchForEmptySearchTypes() throws Exception {
    final Query query = Query.builder().id("query1").query(ElasticsearchQueryString.of("")).timerange(RelativeRange.create(300)).build();
    final Search search = Search.builder().queries(ImmutableSet.of(query)).build();
    final SearchJob job = new SearchJob("deadbeef", search, "admin");
    final ESGeneratedQueryContext queryContext = mock(ESGeneratedQueryContext.class);
    final QueryResult queryResult = backend.doRun(job, query, queryContext);
    assertThat(queryResult).isNotNull();
    assertThat(queryResult.searchTypes()).isEmpty();
    assertThat(queryResult.executionStats()).isNotNull();
    assertThat(queryResult.errors()).isEmpty();
}
Also used : QueryResult(org.graylog.plugins.views.search.QueryResult) Query(org.graylog.plugins.views.search.Query) Search(org.graylog.plugins.views.search.Search) SearchJob(org.graylog.plugins.views.search.SearchJob) Test(org.junit.Test)

Example 4 with QueryResult

use of org.graylog.plugins.views.search.QueryResult in project graylog2-server by Graylog2.

the class ElasticsearchBackendMultiSearchTest method multiSearchResultsAreAssignedToSearchTypes.

@Test
public void multiSearchResultsAreAssignedToSearchTypes() throws Exception {
    final ESGeneratedQueryContext queryContext = this.elasticsearchBackend.generate(searchJob, query, new SearchConfig(Period.ZERO));
    when(jestClient.execute(any(), any())).thenReturn(resultFor(resourceFile("successfulMultiSearchResponse.json")));
    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 : 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 5 with QueryResult

use of org.graylog.plugins.views.search.QueryResult in project graylog2-server by Graylog2.

the class QueryBackend method effectiveTimeRangeForResult.

default AbsoluteRange effectiveTimeRangeForResult(Query query, QueryResult queryResult) {
    final TimeRange effectiveTimeRange = query.globalOverride().flatMap(GlobalOverride::timerange).orElse(query.timerange());
    if (isAllMessages(effectiveTimeRange)) {
        final Optional<AbsoluteRange> effectiveRange = queryResult.searchTypes().values().stream().filter(result -> result instanceof PivotResult).map(result -> ((PivotResult) result).effectiveTimerange()).reduce((prev, next) -> {
            final DateTime from = prev.from().compareTo(next.from()) < 0 ? prev.from() : next.from();
            final DateTime to = prev.to().compareTo(next.to()) < 0 ? next.to() : prev.to();
            return AbsoluteRange.create(from, to);
        });
        if (effectiveRange.isPresent()) {
            return effectiveRange.get();
        }
    }
    return AbsoluteRange.create(effectiveTimeRange.getFrom(), effectiveTimeRange.getTo());
}
Also used : Period(org.joda.time.Period) SearchJob(org.graylog.plugins.views.search.SearchJob) Query(org.graylog.plugins.views.search.Query) Stopwatch(com.google.common.base.Stopwatch) PivotResult(org.graylog.plugins.views.search.searchtypes.pivot.PivotResult) DateTime(org.joda.time.DateTime) Set(java.util.Set) RelativeRange(org.graylog2.plugin.indexer.searches.timeranges.RelativeRange) GlobalOverride(org.graylog.plugins.views.search.GlobalOverride) Objects(java.util.Objects) TimeUnit(java.util.concurrent.TimeUnit) SearchType(org.graylog.plugins.views.search.SearchType) IllegalTimeRangeException(org.graylog.plugins.views.search.errors.IllegalTimeRangeException) AbsoluteRange(org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange) Optional(java.util.Optional) SearchTypeError(org.graylog.plugins.views.search.errors.SearchTypeError) QueryResult(org.graylog.plugins.views.search.QueryResult) TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) QueryError(org.graylog.plugins.views.search.errors.QueryError) TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) PivotResult(org.graylog.plugins.views.search.searchtypes.pivot.PivotResult) AbsoluteRange(org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange) DateTime(org.joda.time.DateTime)

Aggregations

QueryResult (org.graylog.plugins.views.search.QueryResult)18 Test (org.junit.Test)10 SearchJob (org.graylog.plugins.views.search.SearchJob)7 Query (org.graylog.plugins.views.search.Query)6 SearchConfig (org.graylog.plugins.views.search.engine.SearchConfig)6 SearchError (org.graylog.plugins.views.search.errors.SearchError)6 PivotResult (org.graylog.plugins.views.search.searchtypes.pivot.PivotResult)6 ArrayList (java.util.ArrayList)5 SearchTypeError (org.graylog.plugins.views.search.errors.SearchTypeError)5 MultiSearchResponse (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchResponse)5 Optional (java.util.Optional)4 Set (java.util.Set)4 SearchType (org.graylog.plugins.views.search.SearchType)4 QueryError (org.graylog.plugins.views.search.errors.QueryError)4 MultiSearchResult (io.searchbox.core.MultiSearchResult)3 Collections (java.util.Collections)3 List (java.util.List)3 Objects (java.util.Objects)3 Collectors (java.util.stream.Collectors)3 GlobalOverride (org.graylog.plugins.views.search.GlobalOverride)3