use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.Aggregations in project graylog2-server by Graylog2.
the class ESPivotTest method searchResultIncludesDocumentCount.
@Test
public void searchResultIncludesDocumentCount() throws InvalidRangeParametersException {
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.total()).isEqualTo(documentCount);
}
use of org.graylog.shaded.elasticsearch7.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));
}
use of org.graylog.shaded.elasticsearch7.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");
}
use of org.graylog.shaded.elasticsearch7.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")));
}
use of org.graylog.shaded.elasticsearch7.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();
}
Aggregations