Search in sources :

Example 31 with Aggregations

use of org.elasticsearch.search.aggregations.Aggregations in project graylog2-server by Graylog2.

the class ESPivotTest method createTimestampRangeAggregations.

private Aggregations createTimestampRangeAggregations(Double min, Double max) {
    final Min timestampMinAggregation = mock(Min.class);
    when(timestampMinAggregation.getValue()).thenReturn(min);
    when(timestampMinAggregation.getName()).thenReturn("timestamp-min");
    final Max timestampMaxAggregation = mock(Max.class);
    when(timestampMaxAggregation.getValue()).thenReturn(max);
    when(timestampMaxAggregation.getName()).thenReturn("timestamp-max");
    return new Aggregations(ImmutableList.of(timestampMinAggregation, timestampMaxAggregation));
}
Also used : Min(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.metrics.Min) Max(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.metrics.Max) Aggregations(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.Aggregations)

Example 32 with Aggregations

use of org.elasticsearch.search.aggregations.Aggregations in project graylog2-server by Graylog2.

the class ESPivotTest method includesCustomNameinResultIfPresent.

@Test
public void includesCustomNameinResultIfPresent() throws InvalidRangeParametersException {
    final ESPivot esPivot = new ESPivot(Collections.emptyMap(), Collections.emptyMap());
    final Pivot pivot = Pivot.builder().id("somePivotId").name("customPivot").series(Collections.emptyList()).rollup(false).build();
    final long documentCount = 424242;
    returnDocumentCount(queryResult, documentCount);
    final Aggregations 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 = esPivot.doExtractResult(null, query, pivot, queryResult, null, null);
    assertThat(result.name()).contains("customPivot");
}
Also used : Aggregations(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.Aggregations) Pivot(org.graylog.plugins.views.search.searchtypes.pivot.Pivot) ESPivot(org.graylog.storage.elasticsearch7.views.searchtypes.pivot.ESPivot) SearchType(org.graylog.plugins.views.search.SearchType) ESPivot(org.graylog.storage.elasticsearch7.views.searchtypes.pivot.ESPivot) Date(java.util.Date) Test(org.junit.Test)

Example 33 with Aggregations

use of org.elasticsearch.search.aggregations.Aggregations in project graylog2-server by Graylog2.

the class ESPivotTest method searchResultIncludesTimerangeOfPivot.

@Test
public void searchResultIncludesTimerangeOfPivot() throws InvalidRangeParametersException {
    DateTimeUtils.setCurrentMillisFixed(1578584665408L);
    final long documentCount = 424242;
    returnDocumentCount(queryResult, documentCount);
    final Aggregations 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 : 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) Date(java.util.Date) Test(org.junit.Test)

Example 34 with Aggregations

use of org.elasticsearch.search.aggregations.Aggregations in project graylog2-server by Graylog2.

the class ESPivotTest method searchResultForAllMessagesIncludesTimerangeOfDocuments.

@Test
public void searchResultForAllMessagesIncludesTimerangeOfDocuments() throws InvalidRangeParametersException {
    DateTimeUtils.setCurrentMillisFixed(1578584665408L);
    final long documentCount = 424242;
    returnDocumentCount(queryResult, documentCount);
    final Aggregations 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 : 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) Date(java.util.Date) Test(org.junit.Test)

Aggregations

Aggregations (org.elasticsearch.search.aggregations.Aggregations)26 SearchResponse (org.elasticsearch.action.search.SearchResponse)19 Test (org.junit.Test)14 Terms (org.elasticsearch.search.aggregations.bucket.terms.Terms)11 ArrayList (java.util.ArrayList)10 AbstractDaoTest (org.finra.herd.dao.AbstractDaoTest)8 StringTerms (org.elasticsearch.search.aggregations.bucket.terms.StringTerms)7 Aggregations (org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.Aggregations)7 Map (java.util.Map)6 HashMap (java.util.HashMap)5 Nested (org.elasticsearch.search.aggregations.bucket.nested.Nested)5 SearchType (org.graylog.plugins.views.search.SearchType)5 Date (java.util.Date)4 AggregationBuilder (org.elasticsearch.search.aggregations.AggregationBuilder)4 List (java.util.List)3 SearchRequest (org.elasticsearch.action.search.SearchRequest)3 Aggregation (org.elasticsearch.search.aggregations.Aggregation)3 SearchSourceBuilder (org.elasticsearch.search.builder.SearchSourceBuilder)3 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)3 PivotResult (org.graylog.plugins.views.search.searchtypes.pivot.PivotResult)3