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 SummaryNested ClassesModifier and TypeClassDescriptionprotected static interfaceprotected static interfaceprotected static interfaceprotected static interfaceNested classes/interfaces inherited from class org.elasticsearch.search.aggregations.AggregatorAggregator.BucketComparator, Aggregator.Parser, Aggregator.SubAggCollectionMode
- 
Field SummaryFieldsFields inherited from class org.elasticsearch.search.aggregations.AggregatorBasecollectableSubAggregators, DEFAULT_WEIGHT, name, parent, subAggregatorsFields inherited from class org.elasticsearch.search.aggregations.BucketCollectorNO_OP_COLLECTOR
- 
Constructor SummaryConstructorsConstructorDescriptionBucketsAggregator(String name, AggregatorFactories factories, AggregationContext context, Aggregator parent, CardinalityUpperBound bucketCardinality, Map<String,Object> metadata)
- 
Method SummaryModifier 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.AggregatorBaseaddRequestCircuitBreakerBytes, 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.AggregatorbuildAggregations, buildEmptyAggregation, buildTopLevel, collectDebugInfo, resolveSortPathOnValidAgg
- 
Field Details- 
docCountProvider
 
- 
- 
Constructor Details- 
BucketsAggregatorpublic BucketsAggregator(String name, AggregatorFactories factories, AggregationContext context, Aggregator parent, CardinalityUpperBound bucketCardinality, Map<String,Object> metadata) throws IOException- Throws:
- IOException
 
 
- 
- 
Method Details- 
maxBucketOrdpublic final long maxBucketOrd()Return an upper bound of the maximum bucket ordinal seen so far.
- 
growpublic final void grow(long maxBucketOrd)Ensure there are at leastmaxBucketOrdbuckets available.
- 
collectBucketpublic 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
 
- 
collectExistingBucketpublic 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
 
- 
rewriteBucketsMerge 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
- 
incrementBucketDocCountpublic final void incrementBucketDocCount(long bucketOrd, long inc)Utility method to increment the doc counts of the given bucket (identified by the bucket ordinal)
- 
bucketDocCountpublic final long bucketDocCount(long bucketOrd)Utility method to return the number of documents that fell in the given bucket (identified by the bucket ordinal)
- 
prepareSubAggsHook to allow taking an action before building the sub agg results.- Throws:
- IOException
 
- 
buildSubAggsForBucketsprotected 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
 
- 
buildSubAggsForBucketsprotected 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 building
- bucketToOrd- how to convert a bucket into an ordinal
- setAggs- how to set the sub-aggregation results on a bucket
- Throws:
- IOException
 
- 
buildSubAggsForAllBucketsprotected 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 building
- bucketToOrd- how to convert a bucket into an ordinal
- setAggs- how to set the sub-aggregation results on a bucket
- Throws:
- IOException
 
- 
buildAggregationsForFixedBucketCountprotected 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 results
- bucketsPerOwningBucketOrd- how many buckets there are per ord
- bucketBuilder- how to build a bucket
- resultBuilder- how to build a result from buckets
- Throws:
- IOException
 
- 
buildAggregationsForSingleBucketprotected 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 results
- resultBuilder- how to build a result from the sub aggregation results
- Throws:
- IOException
 
- 
buildAggregationsForVariableBucketsprotected 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 results
- bucketOrds- hash of values to the bucket ordinal
- Throws:
- IOException
 
- 
closepublic final void close()Description copied from class:AggregatorBaseCalled upon release of the aggregator.- Specified by:
- closein interface- AutoCloseable
- Specified by:
- closein interface- Closeable
- Specified by:
- closein interface- org.elasticsearch.core.Releasable
- Overrides:
- closein class- AggregatorBase
 
- 
resolveSortPathpublic 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 class- Aggregator
 
- 
bucketComparatorDescription 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 class- Aggregator
 
- 
descendsFromGlobalAggregator
- 
preGetSubLeafCollectorsprotected 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 class- AggregatorBase
- Throws:
- IOException
 
 
-