Search in sources :

Example 6 with DateHistogramInterval

use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval 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

AggregationBuilder (org.elasticsearch.search.aggregations.AggregationBuilder)3 DateHistogramInterval (org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval)3 Date (java.util.Date)2 Nonnull (javax.annotation.Nonnull)2 FilterAggregationBuilder (org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder)2 TermsAggregationBuilder (org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder)2 DateHistogramInterval (org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramInterval)2 DateTime (org.joda.time.DateTime)2 Duration (org.joda.time.Duration)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ZonedDateTime (java.time.ZonedDateTime)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 OptionalLong (java.util.OptionalLong)1 AbstractAggregationBuilder (org.elasticsearch.search.aggregations.AbstractAggregationBuilder)1 GeoGridAggregationBuilder (org.elasticsearch.search.aggregations.bucket.geogrid.GeoGridAggregationBuilder)1 DateHistogramAggregationBuilder (org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder)1 ExtendedBounds (org.elasticsearch.search.aggregations.bucket.histogram.ExtendedBounds)1 HistogramAggregationBuilder (org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregationBuilder)1