Search in sources :

Example 1 with PivotResult

use of org.graylog.plugins.views.search.searchtypes.pivot.PivotResult in project graylog2-server by Graylog2.

the class ESPivotTest method searchResultForAllMessagesIncludesPivotTimerangeForNoDocuments.

@Test
public void searchResultForAllMessagesIncludesPivotTimerangeForNoDocuments() throws InvalidRangeParametersException {
    DateTimeUtils.setCurrentMillisFixed(1578584665408L);
    final long documentCount = 0;
    returnDocumentCount(queryResult, documentCount);
    final Aggregations mockMetricAggregation = createTimestampRangeAggregations(0d, 0d);
    when(queryResult.getAggregations()).thenReturn(mockMetricAggregation);
    when(query.effectiveTimeRange(pivot)).thenReturn(RelativeRange.create(0));
    final SearchType.Result result = this.esPivot.doExtractResult(job, query, pivot, queryResult, aggregations, queryContext);
    final PivotResult pivotResult = (PivotResult) result;
    assertThat(pivotResult.effectiveTimerange()).isEqualTo(AbsoluteRange.create(DateTime.parse("1970-01-01T00:00:00.000Z"), DateTime.parse("2020-01-09T15:44:25.408Z")));
}
Also used : PivotResult(org.graylog.plugins.views.search.searchtypes.pivot.PivotResult) Aggregations(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.Aggregations) SearchType(org.graylog.plugins.views.search.SearchType) Test(org.junit.Test)

Example 2 with PivotResult

use of org.graylog.plugins.views.search.searchtypes.pivot.PivotResult 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 PivotResult

use of org.graylog.plugins.views.search.searchtypes.pivot.PivotResult 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 4 with PivotResult

use of org.graylog.plugins.views.search.searchtypes.pivot.PivotResult in project graylog2-server by Graylog2.

the class ESPivotTest method searchResultForAllMessagesIncludesPivotTimerangeForNoDocuments.

@Test
public void searchResultForAllMessagesIncludesPivotTimerangeForNoDocuments() throws InvalidRangeParametersException {
    DateTimeUtils.setCurrentMillisFixed(1578584665408L);
    final long documentCount = 0;
    when(queryResult.getTotal()).thenReturn(documentCount);
    final MetricAggregation mockMetricAggregation = createTimestampRangeAggregations(null, null);
    when(queryResult.getAggregations()).thenReturn(mockMetricAggregation);
    when(query.effectiveTimeRange(pivot)).thenReturn(RelativeRange.create(0));
    final SearchType.Result result = this.esPivot.doExtractResult(job, query, pivot, queryResult, aggregations, queryContext);
    final PivotResult pivotResult = (PivotResult) result;
    assertThat(pivotResult.effectiveTimerange()).isEqualTo(AbsoluteRange.create(DateTime.parse("1970-01-01T00:00:00.000Z"), DateTime.parse("2020-01-09T15:44:25.408Z")));
}
Also used : MetricAggregation(io.searchbox.core.search.aggregation.MetricAggregation) PivotResult(org.graylog.plugins.views.search.searchtypes.pivot.PivotResult) SearchType(org.graylog.plugins.views.search.SearchType) Test(org.junit.Test)

Example 5 with PivotResult

use of org.graylog.plugins.views.search.searchtypes.pivot.PivotResult in project graylog2-server by Graylog2.

the class ESPivotTest method searchResultIncludesDocumentCount.

@Test
public void searchResultIncludesDocumentCount() throws InvalidRangeParametersException {
    final long documentCount = 424242;
    when(queryResult.getTotal()).thenReturn(documentCount);
    final MetricAggregation mockMetricAggregation = createTimestampRangeAggregations((double) new Date().getTime(), (double) new Date().getTime());
    when(queryResult.getAggregations()).thenReturn(mockMetricAggregation);
    when(query.effectiveTimeRange(pivot)).thenReturn(RelativeRange.create(300));
    final SearchType.Result result = this.esPivot.doExtractResult(job, query, pivot, queryResult, aggregations, queryContext);
    final PivotResult pivotResult = (PivotResult) result;
    assertThat(pivotResult.total()).isEqualTo(documentCount);
}
Also used : MetricAggregation(io.searchbox.core.search.aggregation.MetricAggregation) PivotResult(org.graylog.plugins.views.search.searchtypes.pivot.PivotResult) SearchType(org.graylog.plugins.views.search.SearchType) Date(java.util.Date) Test(org.junit.Test)

Aggregations

PivotResult (org.graylog.plugins.views.search.searchtypes.pivot.PivotResult)18 Test (org.junit.Test)15 SearchType (org.graylog.plugins.views.search.SearchType)9 Date (java.util.Date)6 QueryResult (org.graylog.plugins.views.search.QueryResult)6 MetricAggregation (io.searchbox.core.search.aggregation.MetricAggregation)4 SearchConfig (org.graylog.plugins.views.search.engine.SearchConfig)4 Aggregations (org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.Aggregations)4 AbsoluteRange (org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange)4 SearchTypeError (org.graylog.plugins.views.search.errors.SearchTypeError)3 ArrayList (java.util.ArrayList)2 EventProcessorException (org.graylog.events.processor.EventProcessorException)2 SearchJob (org.graylog.plugins.views.search.SearchJob)2 ElasticsearchQueryString (org.graylog.plugins.views.search.elasticsearch.ElasticsearchQueryString)2 QueryError (org.graylog.plugins.views.search.errors.QueryError)2 MultiSearchResponse (org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.MultiSearchResponse)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Stopwatch (com.google.common.base.Stopwatch)1 ImmutableList (com.google.common.collect.ImmutableList)1 Objects (java.util.Objects)1