Class BucketsAggregator
java.lang.Object
org.elasticsearch.search.aggregations.BucketCollector
org.elasticsearch.search.aggregations.Aggregator
org.elasticsearch.search.aggregations.AggregatorBase
org.elasticsearch.search.aggregations.bucket.BucketsAggregator
- All Implemented Interfaces:
 Closeable,AutoCloseable,org.apache.lucene.search.Collector,org.elasticsearch.core.Releasable
- Direct Known Subclasses:
 AbstractHistogramAggregator,AdjacencyMatrixAggregator,BinaryRangeAggregator,DeferableBucketAggregator,FilterAggregator,FiltersAggregator,GeoGridAggregator,GlobalAggregator,MissingAggregator,NestedAggregator,RangeAggregator,ReverseNestedAggregator
- 
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static interfaceprotected static interfaceprotected static interfaceprotected static interfaceNested classes/interfaces inherited from class org.elasticsearch.search.aggregations.Aggregator
Aggregator.BucketComparator, Aggregator.Parser, Aggregator.SubAggCollectionMode - 
Field Summary
FieldsFields inherited from class org.elasticsearch.search.aggregations.AggregatorBase
collectableSubAggregators, DEFAULT_WEIGHT, name, parent, subAggregatorsFields inherited from class org.elasticsearch.search.aggregations.BucketCollector
NO_OP_COLLECTOR - 
Constructor Summary
ConstructorsConstructorDescriptionBucketsAggregator(String name, AggregatorFactories factories, AggregationContext context, Aggregator parent, CardinalityUpperBound bucketCardinality, Map<String,Object> metadata) - 
Method Summary
Modifier and TypeMethodDescriptionbucketComparator(String key, SortOrder order)Builds a comparator that compares two buckets aggregated by this Aggregator.longbucketDocCount(long bucketOrd)Utility method to return the number of documents that fell in the given bucket (identified by the bucket ordinal)protected <B> InternalAggregation[]buildAggregationsForFixedBucketCount(long[] owningBucketOrds, int bucketsPerOwningBucketOrd, BucketsAggregator.BucketBuilderForFixedCount<B> bucketBuilder, Function<List<B>,InternalAggregation> resultBuilder)Build aggregation results for an aggregator that has a fixed number of buckets per owning ordinal.protected InternalAggregation[]buildAggregationsForSingleBucket(long[] owningBucketOrds, BucketsAggregator.SingleBucketResultBuilder resultBuilder)Build aggregation results for an aggregator that always contain a single bucket.protected <B> InternalAggregation[]buildAggregationsForVariableBuckets(long[] owningBucketOrds, LongKeyedBucketOrds bucketOrds, BucketsAggregator.BucketBuilderForVariable<B> bucketBuilder, BucketsAggregator.ResultBuilderForVariable<B> resultBuilder)Build aggregation results for an aggregator with a varying number oflongkeyed buckets.protected <B> voidbuildSubAggsForAllBuckets(B[][] buckets, ToLongFunction<B> bucketToOrd, BiConsumer<B,InternalAggregations> setAggs)Build the sub aggregation results for a list of buckets and set them on the buckets.protected InternalAggregations[]buildSubAggsForBuckets(long[] bucketOrdsToCollect)Build the results of the sub-aggregations of the buckets at each of the provided ordinals.protected <B> voidbuildSubAggsForBuckets(B[] buckets, ToLongFunction<B> bucketToOrd, BiConsumer<B,InternalAggregations> setAggs)Build the sub aggregation results for a list of buckets and set them on the buckets.voidclose()Called upon release of the aggregator.voidcollectBucket(LeafBucketCollector subCollector, int doc, long bucketOrd)Utility method to collect the given doc in the given bucket (identified by the bucket ordinal)voidcollectExistingBucket(LeafBucketCollector subCollector, int doc, long bucketOrd)Same ascollectBucket(LeafBucketCollector, int, long), but doesn't check if the docCounts needs to be re-sized.static booleandescendsFromGlobalAggregator(Aggregator parent)voidgrow(long maxBucketOrd)Ensure there are at leastmaxBucketOrdbuckets available.voidincrementBucketDocCount(long bucketOrd, long inc)Utility method to increment the doc counts of the given bucket (identified by the bucket ordinal)longReturn an upper bound of the maximum bucket ordinal seen so far.protected voidpreGetSubLeafCollectors(org.apache.lucene.index.LeafReaderContext ctx)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.protected voidprepareSubAggs(long[] ordsToCollect)Hook to allow taking an action before building the sub agg results.Resolve a sort path to the target.voidrewriteBuckets(long newNumBuckets, LongUnaryOperator mergeMap)Merge doc counts.Methods inherited from class org.elasticsearch.search.aggregations.AggregatorBase
addRequestCircuitBreakerBytes, bigArrays, buildEmptySubAggregations, doClose, doPostCollection, doPreCollection, getLeafCollector, getLeafCollector, metadata, name, parent, pointReaderIfAvailable, postCollection, preCollection, scoreMode, searcher, subAggregator, subAggregators, topLevelQuery, toStringMethods inherited from class org.elasticsearch.search.aggregations.Aggregator
buildAggregations, buildEmptyAggregation, buildTopLevel, collectDebugInfo, resolveSortPathOnValidAgg 
- 
Field Details
- 
docCountProvider
 
 - 
 - 
Constructor Details
- 
BucketsAggregator
public BucketsAggregator(String name, AggregatorFactories factories, AggregationContext context, Aggregator parent, CardinalityUpperBound bucketCardinality, Map<String,Object> metadata) throws IOException- Throws:
 IOException
 
 - 
 - 
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 leastmaxBucketOrdbuckets available. - 
collectBucket
public final void collectBucket(LeafBucketCollector subCollector, int doc, long bucketOrd) throws IOExceptionUtility method to collect the given doc in the given bucket (identified by the bucket ordinal)- Throws:
 IOException
 - 
collectExistingBucket
public final void collectExistingBucket(LeafBucketCollector subCollector, int doc, long bucketOrd) throws IOExceptionSame ascollectBucket(LeafBucketCollector, int, long), but doesn't check if the docCounts needs to be re-sized.- Throws:
 IOException
 - 
rewriteBuckets
Merge doc counts. If the Aggregator is delayed then you must also callBestBucketsDeferringCollector.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
 - 
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
Hook to allow taking an action before building the sub agg results.- Throws:
 IOException
 - 
buildSubAggsForBuckets
protected final InternalAggregations[] buildSubAggsForBuckets(long[] bucketOrdsToCollect) throws IOExceptionBuild the results of the sub-aggregations of the buckets at each of the provided ordinals.Most aggregations should probably use something like
buildSubAggsForAllBuckets(Object[][], ToLongFunction, BiConsumer)orbuildAggregationsForVariableBuckets(long[], LongKeyedBucketOrds, BucketBuilderForVariable, ResultBuilderForVariable)orbuildAggregationsForFixedBucketCount(long[], int, BucketBuilderForFixedCount, Function)orbuildAggregationsForSingleBucket(long[], SingleBucketResultBuilder)instead of calling this directly.- Returns:
 - the sub-aggregation results in the same order as the provided array of ordinals
 - Throws:
 IOException
 - 
buildSubAggsForBuckets
protected final <B> void buildSubAggsForBuckets(B[] buckets, ToLongFunction<B> bucketToOrd, BiConsumer<B,InternalAggregations> setAggs) throws IOExceptionBuild 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 buildingbucketToOrd- how to convert a bucket into an ordinalsetAggs- how to set the sub-aggregation results on a bucket- Throws:
 IOException
 - 
buildSubAggsForAllBuckets
protected final <B> void buildSubAggsForAllBuckets(B[][] buckets, ToLongFunction<B> bucketToOrd, BiConsumer<B,InternalAggregations> setAggs) throws IOExceptionBuild 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 buildingbucketToOrd- how to convert a bucket into an ordinalsetAggs- how to set the sub-aggregation results on a bucket- Throws:
 IOException
 - 
buildAggregationsForFixedBucketCount
protected final <B> InternalAggregation[] buildAggregationsForFixedBucketCount(long[] owningBucketOrds, int bucketsPerOwningBucketOrd, BucketsAggregator.BucketBuilderForFixedCount<B> bucketBuilder, Function<List<B>,InternalAggregation> resultBuilder) throws IOExceptionBuild 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 resultsbucketsPerOwningBucketOrd- how many buckets there are per ordbucketBuilder- how to build a bucketresultBuilder- how to build a result from buckets- Throws:
 IOException
 - 
buildAggregationsForSingleBucket
protected final InternalAggregation[] buildAggregationsForSingleBucket(long[] owningBucketOrds, BucketsAggregator.SingleBucketResultBuilder resultBuilder) throws IOExceptionBuild aggregation results for an aggregator that always contain a single bucket.- Parameters:
 owningBucketOrds- owning bucket ordinals for which to build the resultsresultBuilder- how to build a result from the sub aggregation results- Throws:
 IOException
 - 
buildAggregationsForVariableBuckets
protected final <B> InternalAggregation[] buildAggregationsForVariableBuckets(long[] owningBucketOrds, LongKeyedBucketOrds bucketOrds, BucketsAggregator.BucketBuilderForVariable<B> bucketBuilder, BucketsAggregator.ResultBuilderForVariable<B> resultBuilder) throws IOExceptionBuild aggregation results for an aggregator with a varying number oflongkeyed buckets.- Parameters:
 owningBucketOrds- owning bucket ordinals for which to build the resultsbucketOrds- hash of values to the bucket ordinal- Throws:
 IOException
 - 
close
public final void close()Description copied from class:AggregatorBaseCalled upon release of the aggregator.- Specified by:
 closein interfaceAutoCloseable- Specified by:
 closein interfaceCloseable- Specified by:
 closein interfaceorg.elasticsearch.core.Releasable- Overrides:
 closein classAggregatorBase
 - 
resolveSortPath
public Aggregator resolveSortPath(AggregationPath.PathElement next, Iterator<AggregationPath.PathElement> path)Description copied from class:AggregatorResolve a sort path to the target.The default implementation throws an exception but we override it on aggregations that support sorting.
- Overrides:
 resolveSortPathin classAggregator
 - 
bucketComparator
Description copied from class:AggregatorBuilds 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:
 bucketComparatorin classAggregator
 - 
descendsFromGlobalAggregator
 - 
preGetSubLeafCollectors
protected void preGetSubLeafCollectors(org.apache.lucene.index.LeafReaderContext ctx) throws IOExceptionDescription copied from class:AggregatorBaseCan 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:
 preGetSubLeafCollectorsin classAggregatorBase- Throws:
 IOException
 
 -