Search in sources :

Example 1 with BucketOrder

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

the class ESTimeHandler method doCreateAggregation.

@Nonnull
@Override
public Optional<AggregationBuilder> doCreateAggregation(String name, Pivot pivot, Time timeSpec, ESPivot searchTypeHandler, ESGeneratedQueryContext esGeneratedQueryContext, Query query) {
    final DateHistogramInterval dateHistogramInterval = new DateHistogramInterval(timeSpec.interval().toDateInterval(query.effectiveTimeRange(pivot)).toString());
    final Optional<BucketOrder> ordering = orderForPivot(pivot, timeSpec, esGeneratedQueryContext);
    final DateHistogramAggregationBuilder builder = AggregationBuilders.dateHistogram(name).dateHistogramInterval(dateHistogramInterval).field(timeSpec.field()).order(ordering.orElse(BucketOrder.key(true))).format("date_time");
    record(esGeneratedQueryContext, pivot, timeSpec, name, DateHistogramAggregation.class);
    return Optional.of(builder);
}
Also used : BucketOrder(org.graylog.shaded.elasticsearch6.org.elasticsearch.search.aggregations.BucketOrder) DateHistogramAggregationBuilder(org.graylog.shaded.elasticsearch6.org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder) DateHistogramInterval(org.graylog.shaded.elasticsearch6.org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval) Nonnull(javax.annotation.Nonnull)

Example 2 with BucketOrder

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

the class ESValuesHandler method doCreateAggregation.

@Nonnull
@Override
public Optional<AggregationBuilder> doCreateAggregation(String name, Pivot pivot, Values valuesSpec, ESPivot searchTypeHandler, ESGeneratedQueryContext esGeneratedQueryContext, Query query) {
    final List<BucketOrder> ordering = orderListForPivot(pivot, valuesSpec, esGeneratedQueryContext);
    final TermsAggregationBuilder builder = AggregationBuilders.terms(name).minDocCount(1).field(valuesSpec.field()).order(ordering.isEmpty() ? Collections.singletonList(BucketOrder.count(false)) : ordering).size(valuesSpec.limit());
    record(esGeneratedQueryContext, pivot, valuesSpec, name, TermsAggregation.class);
    return Optional.of(builder);
}
Also used : TermsAggregationBuilder(org.graylog.shaded.elasticsearch6.org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder) BucketOrder(org.graylog.shaded.elasticsearch6.org.elasticsearch.search.aggregations.BucketOrder) Nonnull(javax.annotation.Nonnull)

Example 3 with BucketOrder

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

the class ESValuesHandler method doCreateAggregation.

@Nonnull
@Override
public Optional<AggregationBuilder> doCreateAggregation(String name, Pivot pivot, Values valuesSpec, ESPivot searchTypeHandler, ESGeneratedQueryContext esGeneratedQueryContext, Query query) {
    final List<BucketOrder> ordering = orderListForPivot(pivot, valuesSpec, esGeneratedQueryContext);
    final TermsAggregationBuilder builder = AggregationBuilders.terms(name).minDocCount(1).field(valuesSpec.field()).order(ordering.isEmpty() ? Collections.singletonList(BucketOrder.count(false)) : ordering).size(valuesSpec.limit());
    record(esGeneratedQueryContext, pivot, valuesSpec, name, Terms.class);
    return Optional.of(builder);
}
Also used : TermsAggregationBuilder(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder) BucketOrder(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.BucketOrder) Nonnull(javax.annotation.Nonnull)

Example 4 with BucketOrder

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

the class ESTimeHandler method doCreateAggregation.

@Nonnull
@Override
public Optional<AggregationBuilder> doCreateAggregation(String name, Pivot pivot, Time timeSpec, ESPivot searchTypeHandler, ESGeneratedQueryContext esGeneratedQueryContext, Query query) {
    final DateHistogramInterval dateHistogramInterval = new DateHistogramInterval(timeSpec.interval().toDateInterval(query.effectiveTimeRange(pivot)).toString());
    final Optional<BucketOrder> ordering = orderForPivot(pivot, timeSpec, esGeneratedQueryContext);
    final DateHistogramAggregationBuilder builder = AggregationBuilders.dateHistogram(name).field(timeSpec.field()).order(ordering.orElse(BucketOrder.key(true))).format("date_time");
    setInterval(builder, dateHistogramInterval);
    record(esGeneratedQueryContext, pivot, timeSpec, name, ParsedDateHistogram.class);
    return Optional.of(builder);
}
Also used : BucketOrder(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.BucketOrder) DateHistogramAggregationBuilder(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder) DateHistogramInterval(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval) Nonnull(javax.annotation.Nonnull)

Aggregations

Nonnull (javax.annotation.Nonnull)4 BucketOrder (org.graylog.shaded.elasticsearch6.org.elasticsearch.search.aggregations.BucketOrder)2 BucketOrder (org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.BucketOrder)2 DateHistogramAggregationBuilder (org.graylog.shaded.elasticsearch6.org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder)1 DateHistogramInterval (org.graylog.shaded.elasticsearch6.org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval)1 TermsAggregationBuilder (org.graylog.shaded.elasticsearch6.org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder)1 DateHistogramAggregationBuilder (org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder)1 DateHistogramInterval (org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval)1 TermsAggregationBuilder (org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder)1