Search in sources :

Example 6 with MetricAggregation

use of io.searchbox.core.search.aggregation.MetricAggregation in project graylog2-server by Graylog2.

the class ESEventListTest method testSortingOfStreamsInDoExtractResult.

@Test
public void testSortingOfStreamsInDoExtractResult() {
    final ESEventList esEventList = new TestESEventList();
    final SearchJob searchJob = mock(SearchJob.class);
    final Query query = mock(Query.class);
    final SearchResult searchResult = mock(SearchResult.class);
    final MetricAggregation metricAggregation = mock(MetricAggregation.class);
    final ESGeneratedQueryContext queryContext = mock(ESGeneratedQueryContext.class);
    final EventList eventList = EventList.builder().id("search-type-id").streams(ImmutableSet.of("stream-id-1", "stream-id-2")).build();
    final EventList.Result eventResult = (EventList.Result) esEventList.doExtractResult(searchJob, query, eventList, searchResult, metricAggregation, queryContext);
    assertThat(eventResult.events()).containsExactly(eventSummary("find-1", ImmutableSet.of("stream-id-1")), eventSummary("find-2", ImmutableSet.of("stream-id-2")), eventSummary("find-3", ImmutableSet.of("stream-id-1", "stream-id-2")));
}
Also used : Query(org.graylog.plugins.views.search.Query) MetricAggregation(io.searchbox.core.search.aggregation.MetricAggregation) ESEventList(org.graylog.storage.elasticsearch6.views.searchtypes.ESEventList) EventList(org.graylog.plugins.views.search.searchtypes.events.EventList) SearchJob(org.graylog.plugins.views.search.SearchJob) SearchResult(io.searchbox.core.SearchResult) ESEventList(org.graylog.storage.elasticsearch6.views.searchtypes.ESEventList) ESGeneratedQueryContext(org.graylog.storage.elasticsearch6.views.ESGeneratedQueryContext) SearchResult(io.searchbox.core.SearchResult) Test(org.junit.Test)

Example 7 with MetricAggregation

use of io.searchbox.core.search.aggregation.MetricAggregation 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 8 with MetricAggregation

use of io.searchbox.core.search.aggregation.MetricAggregation 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)

Example 9 with MetricAggregation

use of io.searchbox.core.search.aggregation.MetricAggregation in project graylog2-server by Graylog2.

the class ESPivotTest method searchResultForAllMessagesIncludesTimerangeOfDocuments.

@Test
public void searchResultForAllMessagesIncludesTimerangeOfDocuments() throws InvalidRangeParametersException {
    DateTimeUtils.setCurrentMillisFixed(1578584665408L);
    final long documentCount = 424242;
    when(queryResult.getTotal()).thenReturn(documentCount);
    final MetricAggregation mockMetricAggregation = createTimestampRangeAggregations((double) new Date(1547303022000L).getTime(), (double) new Date(1578040943000L).getTime());
    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("2019-01-12T14:23:42.000Z"), DateTime.parse("2020-01-03T08:42:23.000Z")));
    DateTimeUtils.setCurrentMillisSystem();
}
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)

Example 10 with MetricAggregation

use of io.searchbox.core.search.aggregation.MetricAggregation in project graylog2-server by Graylog2.

the class ESPivotTest method searchResultIncludesTimerangeOfPivot.

@Test
public void searchResultIncludesTimerangeOfPivot() throws InvalidRangeParametersException {
    DateTimeUtils.setCurrentMillisFixed(1578584665408L);
    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.effectiveTimerange()).isEqualTo(AbsoluteRange.create(DateTime.parse("2020-01-09T15:39:25.408Z"), 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) Date(java.util.Date) Test(org.junit.Test)

Aggregations

MetricAggregation (io.searchbox.core.search.aggregation.MetricAggregation)18 Test (org.junit.Test)9 SearchResult (io.searchbox.core.SearchResult)7 TermsAggregation (io.searchbox.core.search.aggregation.TermsAggregation)7 SearchType (org.graylog.plugins.views.search.SearchType)7 PivotResult (org.graylog.plugins.views.search.searchtypes.pivot.PivotResult)5 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4 Aggregation (io.searchbox.core.search.aggregation.Aggregation)3 List (java.util.List)3 Map (java.util.Map)3 AbstractDaoTest (org.finra.herd.dao.AbstractDaoTest)3 ResultTypeIndexSearchResponseDto (org.finra.herd.model.dto.ResultTypeIndexSearchResponseDto)3 TagTypeIndexSearchResponseDto (org.finra.herd.model.dto.TagTypeIndexSearchResponseDto)3 Query (org.graylog.plugins.views.search.Query)3 SearchJob (org.graylog.plugins.views.search.SearchJob)3 ESGeneratedQueryContext (org.graylog.storage.elasticsearch6.views.ESGeneratedQueryContext)3 Optional (java.util.Optional)2 Inject (javax.inject.Inject)2 BucketSpec (org.graylog.plugins.views.search.searchtypes.pivot.BucketSpec)2