Search in sources :

Example 66 with Aggregation

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);
}
Also used : ESSearchTypeHandler(org.graylog.storage.elasticsearch7.views.searchtypes.ESSearchTypeHandler) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ElasticsearchClient(org.graylog.storage.elasticsearch7.ElasticsearchClient) InvalidRangeParametersException(org.graylog2.plugin.indexer.searches.timeranges.InvalidRangeParametersException) Provider(javax.inject.Provider) Query(org.graylog.plugins.views.search.Query) Mock(org.mockito.Mock) HashMap(java.util.HashMap) Captor(org.mockito.Captor) Max(org.graylog.plugins.views.search.searchtypes.pivot.series.Max) ESPivotSeriesSpecHandler(org.graylog.storage.elasticsearch7.views.searchtypes.pivot.ESPivotSeriesSpecHandler) ArgumentCaptor(org.mockito.ArgumentCaptor) SearchType(org.graylog.plugins.views.search.SearchType) BucketSpec(org.graylog.plugins.views.search.searchtypes.pivot.BucketSpec) SeriesSpec(org.graylog.plugins.views.search.searchtypes.pivot.SeriesSpec) Map(java.util.Map) FieldTypesLookup(org.graylog.plugins.views.search.elasticsearch.FieldTypesLookup) AbsoluteRange(org.graylog2.plugin.indexer.searches.timeranges.AbsoluteRange) MockitoJUnit(org.mockito.junit.MockitoJUnit) Search(org.graylog.plugins.views.search.Search) Aggregation(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.Aggregation) QueryResult(org.graylog.plugins.views.search.QueryResult) Pivot(org.graylog.plugins.views.search.searchtypes.pivot.Pivot) TimeRange(org.graylog2.plugin.indexer.searches.timeranges.TimeRange) Before(org.junit.Before) SearchJob(org.graylog.plugins.views.search.SearchJob) ImmutableSet(com.google.common.collect.ImmutableSet) SearchRequest(org.graylog.shaded.elasticsearch7.org.elasticsearch.action.search.SearchRequest) ESMaxHandler(org.graylog.storage.elasticsearch7.views.searchtypes.pivot.series.ESMaxHandler) ESPivotBucketSpecHandler(org.graylog.storage.elasticsearch7.views.searchtypes.pivot.ESPivotBucketSpecHandler) Set(java.util.Set) Mockito.times(org.mockito.Mockito.times) ESAverageHandler(org.graylog.storage.elasticsearch7.views.searchtypes.pivot.series.ESAverageHandler) Mockito.verify(org.mockito.Mockito.verify) List(java.util.List) QueryStringDecorators(org.graylog.plugins.views.search.elasticsearch.QueryStringDecorators) Rule(org.junit.Rule) ESPivot(org.graylog.storage.elasticsearch7.views.searchtypes.pivot.ESPivot) MockitoRule(org.mockito.junit.MockitoRule) Average(org.graylog.plugins.views.search.searchtypes.pivot.series.Average) IndexLookup(org.graylog.plugins.views.search.elasticsearch.IndexLookup) Collections(java.util.Collections) ESPivotSeriesSpecHandler(org.graylog.storage.elasticsearch7.views.searchtypes.pivot.ESPivotSeriesSpecHandler) HashMap(java.util.HashMap) ESMaxHandler(org.graylog.storage.elasticsearch7.views.searchtypes.pivot.series.ESMaxHandler) SeriesSpec(org.graylog.plugins.views.search.searchtypes.pivot.SeriesSpec) BucketSpec(org.graylog.plugins.views.search.searchtypes.pivot.BucketSpec) Aggregation(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.Aggregation) ESAverageHandler(org.graylog.storage.elasticsearch7.views.searchtypes.pivot.series.ESAverageHandler) ESPivotBucketSpecHandler(org.graylog.storage.elasticsearch7.views.searchtypes.pivot.ESPivotBucketSpecHandler) ESPivot(org.graylog.storage.elasticsearch7.views.searchtypes.pivot.ESPivot) Before(org.junit.Before)

Example 67 with Aggregation

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));
}
Also used : Values(org.graylog.plugins.views.search.searchtypes.pivot.buckets.Values) SearchSourceBuilder(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.builder.SearchSourceBuilder) Test(org.junit.Test)

Example 68 with Aggregation

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}}");
}
Also used : Values(org.graylog.plugins.views.search.searchtypes.pivot.buckets.Values) Time(org.graylog.plugins.views.search.searchtypes.pivot.buckets.Time) DateTime(org.joda.time.DateTime) DocumentContext(com.jayway.jsonpath.DocumentContext) SearchSourceBuilder(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.builder.SearchSourceBuilder) Test(org.junit.Test)

Aggregations

Aggregation (org.elasticsearch.search.aggregations.Aggregation)53 HashMap (java.util.HashMap)25 SearchResponse (org.elasticsearch.action.search.SearchResponse)24 List (java.util.List)20 Terms (org.elasticsearch.search.aggregations.bucket.terms.Terms)19 ArrayList (java.util.ArrayList)17 MultiBucketsAggregation (org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation)17 ElasticsearchAssertions.assertSearchResponse (org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertSearchResponse)16 Script (org.elasticsearch.script.Script)13 ScriptedMetric (org.elasticsearch.search.aggregations.metrics.scripted.ScriptedMetric)13 Map (java.util.Map)11 SearchSourceBuilder (org.graylog.shaded.elasticsearch7.org.elasticsearch.search.builder.SearchSourceBuilder)10 Test (org.junit.Test)8 StringTerms (org.elasticsearch.search.aggregations.bucket.terms.StringTerms)7 BucketSpec (org.graylog.plugins.views.search.searchtypes.pivot.BucketSpec)6 DateTime (org.joda.time.DateTime)6 Aggregation (org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.Aggregation)5 VertexiumException (org.vertexium.VertexiumException)5 FacetDefinition (io.vertigo.dynamo.collections.metamodel.FacetDefinition)4 IOException (java.io.IOException)4