Search in sources :

Example 1 with DateRangeAggregationBuilder

use of org.graylog.shaded.elasticsearch6.org.elasticsearch.search.aggregations.bucket.range.DateRangeAggregationBuilder in project graylog2-server by Graylog2.

the class ESDateRangeHandler method doCreateAggregation.

@Nonnull
@Override
public Optional<AggregationBuilder> doCreateAggregation(String name, Pivot pivot, DateRangeBucket dateRangeBucket, ESPivot searchTypeHandler, ESGeneratedQueryContext esGeneratedQueryContext, Query query) {
    final DateRangeAggregationBuilder builder = AggregationBuilders.dateRange(name).field(dateRangeBucket.field());
    dateRangeBucket.ranges().forEach(r -> {
        final String from = r.from().map(AbstractDateTime::toString).orElse(null);
        final String to = r.to().map(AbstractDateTime::toString).orElse(null);
        if (from != null && to != null) {
            builder.addRange(from, to);
        } else if (to != null) {
            builder.addUnboundedTo(to);
        } else if (from != null) {
            builder.addUnboundedFrom(from);
        }
    });
    builder.format("date_time");
    builder.keyed(false);
    record(esGeneratedQueryContext, pivot, dateRangeBucket, name, ParsedDateRange.class);
    return Optional.of(builder);
}
Also used : DateRangeAggregationBuilder(org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.range.DateRangeAggregationBuilder) Nonnull(javax.annotation.Nonnull)

Example 2 with DateRangeAggregationBuilder

use of org.graylog.shaded.elasticsearch6.org.elasticsearch.search.aggregations.bucket.range.DateRangeAggregationBuilder in project graylog2-server by Graylog2.

the class ESDateRangeHandler method doCreateAggregation.

@Nonnull
@Override
public Optional<AggregationBuilder> doCreateAggregation(String name, Pivot pivot, DateRangeBucket dateRangeBucket, ESPivot searchTypeHandler, ESGeneratedQueryContext esGeneratedQueryContext, Query query) {
    final DateRangeAggregationBuilder builder = AggregationBuilders.dateRange(name).field(dateRangeBucket.field());
    dateRangeBucket.ranges().forEach(r -> {
        final String from = r.from().map(AbstractDateTime::toString).orElse(null);
        final String to = r.to().map(AbstractDateTime::toString).orElse(null);
        if (from != null && to != null) {
            builder.addRange(from, to);
        } else if (to != null) {
            builder.addUnboundedTo(to);
        } else if (from != null) {
            builder.addUnboundedFrom(from);
        }
    });
    builder.format("date_time");
    builder.keyed(false);
    record(esGeneratedQueryContext, pivot, dateRangeBucket, name, DateRangeAggregation.class);
    return Optional.of(builder);
}
Also used : DateRangeAggregationBuilder(org.graylog.shaded.elasticsearch6.org.elasticsearch.search.aggregations.bucket.range.DateRangeAggregationBuilder) Nonnull(javax.annotation.Nonnull)

Aggregations

Nonnull (javax.annotation.Nonnull)2 DateRangeAggregationBuilder (org.graylog.shaded.elasticsearch6.org.elasticsearch.search.aggregations.bucket.range.DateRangeAggregationBuilder)1 DateRangeAggregationBuilder (org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.bucket.range.DateRangeAggregationBuilder)1