Search in sources :

Example 46 with AggregationBuilder

use of org.graylog.shaded.elasticsearch6.org.elasticsearch.search.aggregations.AggregationBuilder in project vertexium by visallo.

the class ElasticsearchSearchQueryBase method getElasticsearchCalendarFieldAggregation.

private Collection<? extends AggregationBuilder> getElasticsearchCalendarFieldAggregation(CalendarFieldAggregation agg) {
    List<AggregationBuilder> aggs = new ArrayList<>();
    PropertyDefinition propertyDefinition = getPropertyDefinition(agg.getPropertyName());
    if (propertyDefinition == null) {
        throw new VertexiumException("Could not find mapping for property: " + agg.getPropertyName());
    }
    Class propertyDataType = propertyDefinition.getDataType();
    for (String propertyName : getPropertyNames(agg.getPropertyName())) {
        String visibilityHash = getSearchIndex().getPropertyVisibilityHashFromPropertyName(propertyName);
        String aggName = createAggregationName(agg.getAggregationName(), visibilityHash);
        if (propertyDataType == Date.class) {
            HistogramAggregationBuilder histAgg = AggregationBuilders.histogram(aggName);
            histAgg.interval(1);
            if (agg.getMinDocumentCount() != null) {
                histAgg.minDocCount(agg.getMinDocumentCount());
            } else {
                histAgg.minDocCount(1L);
            }
            Script script = new Script(ScriptType.INLINE, "painless", getCalendarFieldAggregationScript(agg, propertyName), ImmutableMap.of("tzId", agg.getTimeZone().getID(), "fieldName", propertyName, "calendarField", agg.getCalendarField()));
            histAgg.script(script);
            for (AggregationBuilder subAgg : getElasticsearchAggregations(agg.getNestedAggregations())) {
                histAgg.subAggregation(subAgg);
            }
            aggs.add(histAgg);
        } else {
            throw new VertexiumException("Only dates are supported for hour of day aggregations");
        }
    }
    return aggs;
}
Also used : HistogramAggregationBuilder(org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregationBuilder) DateHistogramAggregationBuilder(org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder) Script(org.elasticsearch.script.Script) RangeAggregationBuilder(org.elasticsearch.search.aggregations.bucket.range.RangeAggregationBuilder) GeoGridAggregationBuilder(org.elasticsearch.search.aggregations.bucket.geogrid.GeoGridAggregationBuilder) AbstractAggregationBuilder(org.elasticsearch.search.aggregations.AbstractAggregationBuilder) AggregationBuilder(org.elasticsearch.search.aggregations.AggregationBuilder) DateRangeAggregationBuilder(org.elasticsearch.search.aggregations.bucket.range.date.DateRangeAggregationBuilder) PercentilesAggregationBuilder(org.elasticsearch.search.aggregations.metrics.percentiles.PercentilesAggregationBuilder) ExtendedStatsAggregationBuilder(org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStatsAggregationBuilder) TermsAggregationBuilder(org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder) HistogramAggregationBuilder(org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregationBuilder) DateHistogramAggregationBuilder(org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder)

Example 47 with AggregationBuilder

use of org.graylog.shaded.elasticsearch6.org.elasticsearch.search.aggregations.AggregationBuilder 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 48 with AggregationBuilder

use of org.graylog.shaded.elasticsearch6.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, AvgAggregation.class);
    return Optional.of(avg);
}
Also used : AvgAggregationBuilder(org.graylog.shaded.elasticsearch6.org.elasticsearch.search.aggregations.metrics.avg.AvgAggregationBuilder) Nonnull(javax.annotation.Nonnull)

Example 49 with AggregationBuilder

use of org.graylog.shaded.elasticsearch6.org.elasticsearch.search.aggregations.AggregationBuilder 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 50 with AggregationBuilder

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

the class ESCardinalityHandler method doCreateAggregation.

@Nonnull
@Override
public Optional<AggregationBuilder> doCreateAggregation(String name, Pivot pivot, Cardinality cardinalitySpec, ESPivot searchTypeHandler, ESGeneratedQueryContext queryContext) {
    final CardinalityAggregationBuilder card = AggregationBuilders.cardinality(name).field(cardinalitySpec.field());
    record(queryContext, pivot, cardinalitySpec, name, CardinalityAggregation.class);
    return Optional.of(card);
}
Also used : CardinalityAggregationBuilder(org.graylog.shaded.elasticsearch6.org.elasticsearch.search.aggregations.metrics.cardinality.CardinalityAggregationBuilder) Nonnull(javax.annotation.Nonnull)

Aggregations

AggregationBuilder (org.elasticsearch.search.aggregations.AggregationBuilder)39 TermsAggregationBuilder (org.elasticsearch.search.aggregations.bucket.terms.TermsAggregationBuilder)28 Nonnull (javax.annotation.Nonnull)14 FilterAggregationBuilder (org.elasticsearch.search.aggregations.bucket.filter.FilterAggregationBuilder)13 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)10 AbstractAggregationBuilder (org.elasticsearch.search.aggregations.AbstractAggregationBuilder)10 SumAggregationBuilder (org.elasticsearch.search.aggregations.metrics.SumAggregationBuilder)8 CardinalityAggregationBuilder (org.elasticsearch.search.aggregations.metrics.cardinality.CardinalityAggregationBuilder)8 ArrayList (java.util.ArrayList)7 RangeAggregationBuilder (org.elasticsearch.search.aggregations.bucket.range.RangeAggregationBuilder)7 DateRangeAggregationBuilder (org.elasticsearch.search.aggregations.bucket.range.date.DateRangeAggregationBuilder)7 Map (java.util.Map)6 SearchResponse (org.elasticsearch.action.search.SearchResponse)6 GeoGridAggregationBuilder (org.elasticsearch.search.aggregations.bucket.geogrid.GeoGridAggregationBuilder)6 DateHistogramAggregationBuilder (org.elasticsearch.search.aggregations.bucket.histogram.DateHistogramAggregationBuilder)6 HistogramAggregationBuilder (org.elasticsearch.search.aggregations.bucket.histogram.HistogramAggregationBuilder)6 PercentilesAggregationBuilder (org.elasticsearch.search.aggregations.metrics.percentiles.PercentilesAggregationBuilder)6 ExtendedStatsAggregationBuilder (org.elasticsearch.search.aggregations.metrics.stats.extended.ExtendedStatsAggregationBuilder)6 BucketSelectorPipelineAggregationBuilder (org.elasticsearch.search.aggregations.pipeline.bucketselector.BucketSelectorPipelineAggregationBuilder)6 HashMap (java.util.HashMap)5