Class Aggregator

java.lang.Object
org.elasticsearch.search.aggregations.BucketCollector
org.elasticsearch.search.aggregations.Aggregator
All Implemented Interfaces:
Closeable, AutoCloseable, org.apache.lucene.search.Collector, org.elasticsearch.core.Releasable
Direct Known Subclasses:
AdaptingAggregator, AggregatorBase, DeferringBucketCollector.WrappedAggregator, ProfilingAggregator

public abstract class Aggregator extends BucketCollector implements org.elasticsearch.core.Releasable
An Aggregator.

Be careful when adding methods to this class. If possible make sure they have sensible default implementations.

  • Constructor Details

    • Aggregator

      public Aggregator()
  • Method Details

    • name

      public abstract String name()
      Return the name of this aggregator.
    • parent

      public abstract Aggregator parent()
      Return the parent aggregator.
    • subAggregator

      public abstract Aggregator subAggregator(String name)
      Return the sub aggregator with the provided name.
    • resolveSortPathOnValidAgg

      public final Aggregator resolveSortPathOnValidAgg(AggregationPath.PathElement next, Iterator<AggregationPath.PathElement> path)
      Resolve the next step of the sort path as though this aggregation supported sorting. This is usually the "first step" when resolving a sort path because most aggs that support sorting their buckets aren't valid in the middle of a sort path.

      For example, the terms aggs supports sorting its buckets, but that sort path itself can't contain a different terms aggregation.

    • resolveSortPath

      Resolve a sort path to the target.

      The default implementation throws an exception but we override it on aggregations that support sorting.

    • bucketComparator

      public Aggregator.BucketComparator bucketComparator(String key, SortOrder order)
      Builds a comparator that compares two buckets aggregated by this Aggregator.

      The default implementation throws an exception but we override it on aggregations that support sorting.

    • buildAggregations

      public abstract InternalAggregation[] buildAggregations(long[] ordsToCollect) throws IOException
      Build the results of this aggregation.
      Parameters:
      ordsToCollect - the ordinals of the buckets that we want to collect from this aggregation
      Returns:
      the results for each ordinal, in the same order as the array of ordinals
      Throws:
      IOException
    • buildTopLevel

      public final InternalAggregation buildTopLevel() throws IOException
      Build the result of this aggregation if it is at the "top level" of the aggregation tree. If, instead, it is a sub-aggregation of another aggregation then the aggregation that contains it will call buildAggregations(long[]).
      Throws:
      IOException
    • buildEmptyAggregation

      public abstract InternalAggregation buildEmptyAggregation()
      Build an empty aggregation.
    • collectDebugInfo

      public void collectDebugInfo(BiConsumer<String,Object> add)
      Collect debug information to add to the profiling results. This will only be called if the aggregation is being profiled.

      Well behaved implementations will always call the superclass implementation just in case it has something interesting. They will also only add objects which can be serialized with StreamOutput.writeGenericValue(Object) and XContentBuilder.value(Object). And they'll have an integration test.

    • subAggregators

      public abstract Aggregator[] subAggregators()
      Get the aggregators running under this one.