use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.Aggregation in project graylog2-server by Graylog2.
the class ElasticsearchBackendGeneratedRequestTestBase method setUpSUT.
@Before
public void setUpSUT() {
this.elasticSearchTypeHandlers = new HashMap<>();
final Map<String, ESPivotBucketSpecHandler<? extends BucketSpec, ? extends Aggregation>> bucketHandlers = Collections.emptyMap();
final Map<String, ESPivotSeriesSpecHandler<? extends SeriesSpec, ? extends Aggregation>> seriesHandlers = new HashMap<>();
seriesHandlers.put(Average.NAME, new ESAverageHandler());
seriesHandlers.put(Max.NAME, new ESMaxHandler());
elasticSearchTypeHandlers.put(Pivot.NAME, () -> new ESPivot(bucketHandlers, seriesHandlers));
this.elasticsearchBackend = new ElasticsearchBackend(elasticSearchTypeHandlers, client, indexLookup, new QueryStringDecorators.Fake(), (elasticsearchBackend, ssb, job, query) -> new ESGeneratedQueryContext(elasticsearchBackend, ssb, job, query, fieldTypesLookup), false);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.Aggregation in project graylog2-server by Graylog2.
the class ESPivotTest method generatesQueryWhenOnlyColumnPivotsArePresent.
@Test
public void generatesQueryWhenOnlyColumnPivotsArePresent() {
final SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
final ESPivotBucketSpecHandler<? extends BucketSpec, ? extends Aggregation> bucketHandler = mock(ESValuesHandler.class);
bucketHandlers.put(Values.NAME, bucketHandler);
when(queryContext.searchSourceBuilder(pivot)).thenReturn(searchSourceBuilder);
when(queryContext.nextName()).thenReturn("agg-1");
final Values values = Values.builder().field("action").limit(10).build();
when(pivot.columnGroups()).thenReturn(Collections.singletonList(values));
this.esPivot.doGenerateQueryPart(job, query, pivot, queryContext);
verify(bucketHandler, times(1)).createAggregation(eq("agg-1"), eq(pivot), eq(values), eq(this.esPivot), eq(queryContext), eq(query));
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.Aggregation in project graylog2-server by Graylog2.
the class ESPivotTest method columnPivotsShouldBeNested.
@Test
public void columnPivotsShouldBeNested() {
final SearchSourceBuilder searchSourceBuilder = new SearchSourceBuilder();
final ESPivotBucketSpecHandler<? extends BucketSpec, ? extends Aggregation> valuesBucketHandler = mock(ESValuesHandler.class);
mockBucketSpecGeneratesComparableString(valuesBucketHandler);
final ESPivotBucketSpecHandler<? extends BucketSpec, ? extends Aggregation> timeBucketHandler = mock(ESTimeHandler.class);
mockBucketSpecGeneratesComparableString(timeBucketHandler);
bucketHandlers.put(Values.NAME, valuesBucketHandler);
bucketHandlers.put(Time.NAME, timeBucketHandler);
when(queryContext.searchSourceBuilder(pivot)).thenReturn(searchSourceBuilder);
when(queryContext.nextName()).thenReturn("values-agg", "time-agg");
final Values values = Values.builder().field("action").limit(10).build();
final Time time = Time.builder().field("timestamp").interval(AutoInterval.create()).build();
when(pivot.columnGroups()).thenReturn(ImmutableList.of(values, time));
this.esPivot.doGenerateQueryPart(job, query, pivot, queryContext);
verify(valuesBucketHandler, times(1)).createAggregation(eq("values-agg"), eq(pivot), eq(values), eq(this.esPivot), eq(queryContext), eq(query));
verify(timeBucketHandler, times(1)).createAggregation(eq("time-agg"), eq(pivot), eq(time), eq(this.esPivot), eq(queryContext), eq(query));
final DocumentContext context = JsonPath.parse(searchSourceBuilder.toString());
extractAggregation(context, "values-agg").isEqualTo("Values{type=values, field=action, limit=10}");
extractAggregation(context, "values-agg.time-agg").isEqualTo("Time{type=time, field=timestamp, interval=AutoInterval{type=auto, scaling=1.0}}");
}
Aggregations