Class BucketsAggregator

All Implemented Interfaces:
java.io.Closeable, java.lang.AutoCloseable, org.apache.lucene.search.Collector, Releasable
Direct Known Subclasses:
AbstractHistogramAggregator, AdjacencyMatrixAggregator, BinaryRangeAggregator, DeferableBucketAggregator, FilterAggregator, FiltersAggregator, GeoGridAggregator, GlobalAggregator, MissingAggregator, NestedAggregator, RangeAggregator, ReverseNestedAggregator

public abstract class BucketsAggregator
extends AggregatorBase
  • Field Details

  • Constructor Details

  • Method Details

    • maxBucketOrd

      public final long maxBucketOrd()
      Return an upper bound of the maximum bucket ordinal seen so far.
    • grow

      public final void grow​(long maxBucketOrd)
      Ensure there are at least maxBucketOrd buckets available.
    • collectBucket

      public final void collectBucket​(LeafBucketCollector subCollector, int doc, long bucketOrd) throws java.io.IOException
      Utility method to collect the given doc in the given bucket (identified by the bucket ordinal)
      Throws:
      java.io.IOException
    • collectExistingBucket

      public final void collectExistingBucket​(LeafBucketCollector subCollector, int doc, long bucketOrd) throws java.io.IOException
      Same as collectBucket(LeafBucketCollector, int, long), but doesn't check if the docCounts needs to be re-sized.
      Throws:
      java.io.IOException
    • rewriteBuckets

      public final void rewriteBuckets​(long newNumBuckets, java.util.function.LongUnaryOperator mergeMap)
      Merge doc counts. If the Aggregator is delayed then you must also call BestBucketsDeferringCollector.rewriteBuckets(LongUnaryOperator) to merge the delayed buckets.
      Parameters:
      mergeMap - a unary operator which maps a bucket's ordinal to the ordinal it should be merged with. If a bucket's ordinal is mapped to -1 then the bucket is removed entirely.
    • getDocCounts

      public LongArray getDocCounts()
    • incrementBucketDocCount

      public final void incrementBucketDocCount​(long bucketOrd, long inc)
      Utility method to increment the doc counts of the given bucket (identified by the bucket ordinal)
    • bucketDocCount

      public final long bucketDocCount​(long bucketOrd)
      Utility method to return the number of documents that fell in the given bucket (identified by the bucket ordinal)
    • prepareSubAggs

      protected void prepareSubAggs​(long[] ordsToCollect) throws java.io.IOException
      Hook to allow taking an action before building the sub agg results.
      Throws:
      java.io.IOException
    • buildSubAggsForBuckets

      protected final InternalAggregations[] buildSubAggsForBuckets​(long[] bucketOrdsToCollect) throws java.io.IOException
      Returns:
      the sub-aggregation results in the same order as the provided array of ordinals
      Throws:
      java.io.IOException
    • buildSubAggsForBuckets

      protected final <B> void buildSubAggsForBuckets​(B[] buckets, java.util.function.ToLongFunction<B> bucketToOrd, java.util.function.BiConsumer<B,​InternalAggregations> setAggs) throws java.io.IOException
      Build the sub aggregation results for a list of buckets and set them on the buckets. This is usually used by aggregations that are selective in which bucket they build. They use some mechanism of selecting a list of buckets to build use this method to "finish" building the results.
      Parameters:
      buckets - the buckets to finish building
      bucketToOrd - how to convert a bucket into an ordinal
      setAggs - how to set the sub-aggregation results on a bucket
      Throws:
      java.io.IOException
    • buildSubAggsForAllBuckets

      protected final <B> void buildSubAggsForAllBuckets​(B[][] buckets, java.util.function.ToLongFunction<B> bucketToOrd, java.util.function.BiConsumer<B,​InternalAggregations> setAggs) throws java.io.IOException
      Build the sub aggregation results for a list of buckets and set them on the buckets. This is usually used by aggregations that are selective in which bucket they build. They use some mechanism of selecting a list of buckets to build use this method to "finish" building the results.
      Parameters:
      buckets - the buckets to finish building
      bucketToOrd - how to convert a bucket into an ordinal
      setAggs - how to set the sub-aggregation results on a bucket
      Throws:
      java.io.IOException
    • buildAggregationsForFixedBucketCount

      protected final <B> InternalAggregation[] buildAggregationsForFixedBucketCount​(long[] owningBucketOrds, int bucketsPerOwningBucketOrd, BucketsAggregator.BucketBuilderForFixedCount<B> bucketBuilder, java.util.function.Function<java.util.List<B>,​InternalAggregation> resultBuilder) throws java.io.IOException
      Build aggregation results for an aggregator that has a fixed number of buckets per owning ordinal.
      Type Parameters:
      B - the type of the bucket
      Parameters:
      owningBucketOrds - owning bucket ordinals for which to build the results
      bucketsPerOwningBucketOrd - how many buckets there are per ord
      bucketBuilder - how to build a bucket
      resultBuilder - how to build a result from buckets
      Throws:
      java.io.IOException
    • buildAggregationsForSingleBucket

      protected final InternalAggregation[] buildAggregationsForSingleBucket​(long[] owningBucketOrds, BucketsAggregator.SingleBucketResultBuilder resultBuilder) throws java.io.IOException
      Build aggregation results for an aggregator that always contain a single bucket.
      Parameters:
      owningBucketOrds - owning bucket ordinals for which to build the results
      resultBuilder - how to build a result from the sub aggregation results
      Throws:
      java.io.IOException
    • buildAggregationsForVariableBuckets

      protected final <B> InternalAggregation[] buildAggregationsForVariableBuckets​(long[] owningBucketOrds, LongKeyedBucketOrds bucketOrds, BucketsAggregator.BucketBuilderForVariable<B> bucketBuilder, BucketsAggregator.ResultBuilderForVariable<B> resultBuilder) throws java.io.IOException
      Build aggregation results for an aggregator with a varying number of long keyed buckets.
      Parameters:
      owningBucketOrds - owning bucket ordinals for which to build the results
      bucketOrds - hash of values to the bucket ordinal
      Throws:
      java.io.IOException
    • close

      public final void close()
      Description copied from class: AggregatorBase
      Called upon release of the aggregator.
      Specified by:
      close in interface java.lang.AutoCloseable
      Specified by:
      close in interface java.io.Closeable
      Specified by:
      close in interface Releasable
      Overrides:
      close in class AggregatorBase
    • resolveSortPath

      public Aggregator resolveSortPath​(AggregationPath.PathElement next, java.util.Iterator<AggregationPath.PathElement> path)
      Description copied from class: Aggregator
      Resolve a sort path to the target.

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

      Overrides:
      resolveSortPath in class Aggregator
    • bucketComparator

      public Aggregator.BucketComparator bucketComparator​(java.lang.String key, SortOrder order)
      Description copied from class: Aggregator
      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.

      Overrides:
      bucketComparator in class Aggregator
    • descendsFromGlobalAggregator

      public static boolean descendsFromGlobalAggregator​(Aggregator parent)
    • preGetSubLeafCollectors

      protected void preGetSubLeafCollectors​(org.apache.lucene.index.LeafReaderContext ctx) throws java.io.IOException
      Description copied from class: AggregatorBase
      Can be overridden by aggregator implementations that like the perform an operation before the leaf collectors of children aggregators are instantiated for the next segment.
      Overrides:
      preGetSubLeafCollectors in class AggregatorBase
      Throws:
      java.io.IOException