Search in sources :

Example 1 with Time

use of org.graylog.plugins.views.search.searchtypes.pivot.buckets.Time in project graylog2-server by Graylog2.

the class ESPivotTest method mixedPivotsShouldBeNested.

@Test
public void mixedPivotsShouldBeNested() {
    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("time-agg", "values-agg");
    final Time time = Time.builder().field("timestamp").interval(AutoInterval.create()).build();
    final Values values = Values.builder().field("action").limit(10).build();
    when(pivot.rowGroups()).thenReturn(Collections.singletonList(time));
    when(pivot.columnGroups()).thenReturn(Collections.singletonList(values));
    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, "time-agg").isEqualTo("Time{type=time, field=timestamp, interval=AutoInterval{type=auto, scaling=1.0}}");
    extractAggregation(context, "time-agg.values-agg").isEqualTo("Values{type=values, field=action, limit=10}");
}
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)

Example 2 with Time

use of org.graylog.plugins.views.search.searchtypes.pivot.buckets.Time in project graylog2-server by Graylog2.

the class ESPivotTest method rowPivotsShouldBeNested.

@Test
public void rowPivotsShouldBeNested() {
    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("time-agg", "values-agg");
    final Time time = Time.builder().field("timestamp").interval(AutoInterval.create()).build();
    final Values values = Values.builder().field("action").limit(10).build();
    when(pivot.rowGroups()).thenReturn(ImmutableList.of(time, values));
    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, "time-agg").isEqualTo("Time{type=time, field=timestamp, interval=AutoInterval{type=auto, scaling=1.0}}");
    extractAggregation(context, "time-agg.values-agg").isEqualTo("Values{type=values, field=action, limit=10}");
}
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)

Example 3 with Time

use of org.graylog.plugins.views.search.searchtypes.pivot.buckets.Time in project graylog2-server by Graylog2.

the class ESPivotTest method rowPivotsShouldBeNested.

@Test
public void rowPivotsShouldBeNested() {
    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("time-agg", "values-agg");
    final Time time = Time.builder().field("timestamp").interval(AutoInterval.create()).build();
    final Values values = Values.builder().field("action").limit(10).build();
    when(pivot.rowGroups()).thenReturn(ImmutableList.of(time, values));
    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, "time-agg").isEqualTo("Time{type=time, field=timestamp, interval=AutoInterval{type=auto, scaling=1.0}}");
    extractAggregation(context, "time-agg.values-agg").isEqualTo("Values{type=values, field=action, limit=10}");
}
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.elasticsearch6.org.elasticsearch.search.builder.SearchSourceBuilder) Test(org.junit.Test)

Example 4 with Time

use of org.graylog.plugins.views.search.searchtypes.pivot.buckets.Time in project graylog2-server by Graylog2.

the class ESPivotTest method mixedPivotsShouldBeNested.

@Test
public void mixedPivotsShouldBeNested() {
    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("time-agg", "values-agg");
    final Time time = Time.builder().field("timestamp").interval(AutoInterval.create()).build();
    final Values values = Values.builder().field("action").limit(10).build();
    when(pivot.rowGroups()).thenReturn(Collections.singletonList(time));
    when(pivot.columnGroups()).thenReturn(Collections.singletonList(values));
    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, "time-agg").isEqualTo("Time{type=time, field=timestamp, interval=AutoInterval{type=auto, scaling=1.0}}");
    extractAggregation(context, "time-agg.values-agg").isEqualTo("Values{type=values, field=action, limit=10}");
}
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.elasticsearch6.org.elasticsearch.search.builder.SearchSourceBuilder) Test(org.junit.Test)

Example 5 with Time

use of org.graylog.plugins.views.search.searchtypes.pivot.buckets.Time 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.elasticsearch6.org.elasticsearch.search.builder.SearchSourceBuilder) Test(org.junit.Test)

Aggregations

DocumentContext (com.jayway.jsonpath.DocumentContext)6 Time (org.graylog.plugins.views.search.searchtypes.pivot.buckets.Time)6 Values (org.graylog.plugins.views.search.searchtypes.pivot.buckets.Values)6 DateTime (org.joda.time.DateTime)6 Test (org.junit.Test)6 SearchSourceBuilder (org.graylog.shaded.elasticsearch6.org.elasticsearch.search.builder.SearchSourceBuilder)3 SearchSourceBuilder (org.graylog.shaded.elasticsearch7.org.elasticsearch.search.builder.SearchSourceBuilder)3