use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.AggregationBuilder 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);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.AggregationBuilder in project graylog2-server by Graylog2.
the class ESAverageHandler method doCreateAggregation.
@Nonnull
@Override
public Optional<AggregationBuilder> doCreateAggregation(String name, Pivot pivot, Average avgSpec, ESPivot searchTypeHandler, ESGeneratedQueryContext queryContext) {
final AvgAggregationBuilder avg = AggregationBuilders.avg(name).field(avgSpec.field());
record(queryContext, pivot, avgSpec, name, Avg.class);
return Optional.of(avg);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.AggregationBuilder in project graylog2-server by Graylog2.
the class ESCountHandler method doCreateAggregation.
@Nonnull
@Override
public Optional<AggregationBuilder> doCreateAggregation(String name, Pivot pivot, Count count, ESPivot searchTypeHandler, ESGeneratedQueryContext queryContext) {
final String field = count.field();
if (field == null) {
// doc_count is always present in elasticsearch's bucket aggregations, no need to add it
return Optional.empty();
} else {
// the request was for a field count, we have to add a value_count sub aggregation
final ValueCountAggregationBuilder value = AggregationBuilders.count(name).field(field);
record(queryContext, pivot, count, name, ValueCount.class);
return Optional.of(value);
}
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.AggregationBuilder in project graylog2-server by Graylog2.
the class ESMaxHandler method doCreateAggregation.
@Nonnull
@Override
public Optional<AggregationBuilder> doCreateAggregation(String name, Pivot pivot, Max maxSpec, ESPivot searchTypeHandler, ESGeneratedQueryContext queryContext) {
final MaxAggregationBuilder max = AggregationBuilders.max(name).field(maxSpec.field());
record(queryContext, pivot, maxSpec, name, org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.metrics.Max.class);
return Optional.of(max);
}
use of org.graylog.shaded.elasticsearch7.org.elasticsearch.search.aggregations.AggregationBuilder in project graylog2-server by Graylog2.
the class ESPercentilesHandler method doCreateAggregation.
@Nonnull
@Override
public Optional<AggregationBuilder> doCreateAggregation(String name, Pivot pivot, Percentile percentileSpec, ESPivot searchTypeHandler, ESGeneratedQueryContext queryContext) {
final PercentilesAggregationBuilder percentiles = AggregationBuilders.percentiles(name).field(percentileSpec.field()).percentiles(percentileSpec.percentile());
record(queryContext, pivot, percentileSpec, name, Percentiles.class);
return Optional.of(percentiles);
}
Aggregations