Module org.elasticsearch.server
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,Releasable
- Direct Known Subclasses:
AbstractHistogramAggregator,BinaryRangeAggregator,CompositeAggregator,DeferableBucketAggregator,FiltersAggregator,GeoGridAggregator,GlobalAggregator,IpPrefixAggregator,MissingAggregator,NestedAggregator,RandomSamplerAggregator,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.SubAggCollectionModeNested classes/interfaces inherited from class org.elasticsearch.search.aggregations.BucketCollector
BucketCollector.BucketCollectorWrapper -
Field Summary
FieldsFields inherited from class org.elasticsearch.search.aggregations.AggregatorBase
collectableSubAggregators, context, DEFAULT_WEIGHT, name, parent, subAggregatorsFields inherited from class org.elasticsearch.search.aggregations.BucketCollector
NO_OP_BUCKET_COLLECTOR, NO_OP_COLLECTOR -
Constructor Summary
ConstructorsConstructorDescriptionBucketsAggregator(String name, AggregatorFactories factories, AggregationContext aggCtx, 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.final longbucketDocCount(long bucketOrd) Utility method to return the number of documents that fell in the given bucket (identified by the bucket ordinal)protected final <B> InternalAggregation[]buildAggregationsForFixedBucketCount(LongArray 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 final InternalAggregation[]buildAggregationsForSingleBucket(LongArray owningBucketOrds, BucketsAggregator.SingleBucketResultBuilder resultBuilder) Build aggregation results for an aggregator that always contain a single bucket.protected final <B> InternalAggregation[]buildAggregationsForVariableBuckets(LongArray owningBucketOrds, LongKeyedBucketOrds bucketOrds, BucketsAggregator.BucketBuilderForVariable<B> bucketBuilder, BucketsAggregator.ResultBuilderForVariable<B> resultBuilder) Build aggregation results for an aggregator with a varying number oflongkeyed buckets.protected final <B> voidbuildSubAggsForAllBuckets(ObjectArray<B[]> buckets, ToLongFunction<B> bucketToOrd, BiConsumer<B, InternalAggregations> setAggs) Similarly tobuildSubAggsForAllBuckets(ObjectArray, LongArray, BiConsumer)but it needs to build the bucket ordinals.protected final <B> voidbuildSubAggsForAllBuckets(ObjectArray<B[]> buckets, LongArray bucketOrdsToCollect, BiConsumer<B, InternalAggregations> setAggs) Build the sub aggregation results for a list of buckets and set them on the buckets.protected final IntFunction<InternalAggregations> buildSubAggsForBuckets(LongArray bucketOrdsToCollect) Build the results of the sub-aggregations of the buckets at each of the provided ordinals.protected final voidThis method should be called whenever a new bucket object is created.final voidclose()Called upon release of the aggregator.final voidcollectBucket(LeafBucketCollector subCollector, int doc, long bucketOrd) Utility method to collect the given doc in the given bucket (identified by the bucket ordinal)final 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 booleanfinal voidgrow(long maxBucketOrd) Ensure there are at leastmaxBucketOrdbuckets available.final voidincrementBucketDocCount(long bucketOrd, long inc) Utility method to increment the doc counts of the given bucket (identified by the bucket ordinal)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(LongArray ordsToCollect) Hook to allow taking an action before building the sub agg results.Resolve a sort path to the target.final voidrewriteBuckets(long newNumBuckets, LongUnaryOperator mergeMap) Merge doc counts.Methods inherited from class org.elasticsearch.search.aggregations.AggregatorBase
addRequestCircuitBreakerBytes, bigArrays, buildAggregations, buildEmptySubAggregations, checkRealMemoryCB, doClose, doPostCollection, doPreCollection, getLeafCollector, getLeafCollector, metadata, name, parent, pointReaderIfAvailable, postCollection, preCollection, releaseAggregations, scoreMode, searcher, subAggregator, subAggregators, topLevelQuery, toStringMethods inherited from class org.elasticsearch.search.aggregations.Aggregator
buildAggregations, buildEmptyAggregation, buildTopLevel, collectDebugInfo, resolveSortPathOnValidAggMethods inherited from class org.elasticsearch.search.aggregations.BucketCollector
asCollector
-
Field Details
-
docCountProvider
-
-
Constructor Details
-
BucketsAggregator
public BucketsAggregator(String name, AggregatorFactories factories, AggregationContext aggCtx, Aggregator parent, CardinalityUpperBound bucketCardinality, Map<String, Object> metadata) throws IOException- Throws:
IOException
-
-
Method Details
-
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 IOException Utility 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 IOException Same 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 IntFunction<InternalAggregations> buildSubAggsForBuckets(LongArray bucketOrdsToCollect) throws IOException Build the results of the sub-aggregations of the buckets at each of the provided ordinals.Most aggregations should probably use something like
buildSubAggsForAllBuckets(ObjectArray, LongArray, BiConsumer)orbuildSubAggsForAllBuckets(ObjectArray, ToLongFunction, BiConsumer)orbuildAggregationsForVariableBuckets(LongArray, LongKeyedBucketOrds, BucketBuilderForVariable, ResultBuilderForVariable)orbuildAggregationsForFixedBucketCount(LongArray, int, BucketBuilderForFixedCount, Function)orbuildAggregationsForSingleBucket(LongArray, SingleBucketResultBuilder)instead of calling this directly.- Returns:
- the sub-aggregation results in the same order as the provided array of ordinals
- Throws:
IOException
-
buildSubAggsForAllBuckets
protected final <B> void buildSubAggsForAllBuckets(ObjectArray<B[]> buckets, ToLongFunction<B> bucketToOrd, BiConsumer<B, InternalAggregations> setAggs) throws IOExceptionSimilarly tobuildSubAggsForAllBuckets(ObjectArray, LongArray, BiConsumer)but it needs to build the bucket ordinals. This method usually requires for buckets to contain the bucket ordinal.- 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(ObjectArray<B[]> buckets, LongArray bucketOrdsToCollect, 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 buildingbucketOrdsToCollect- bucket ordinalssetAggs- how to set the sub-aggregation results on a bucket- Throws:
IOException
-
buildAggregationsForFixedBucketCount
protected final <B> InternalAggregation[] buildAggregationsForFixedBucketCount(LongArray 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(LongArray owningBucketOrds, BucketsAggregator.SingleBucketResultBuilder resultBuilder) throws IOException Build 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(LongArray owningBucketOrds, LongKeyedBucketOrds bucketOrds, BucketsAggregator.BucketBuilderForVariable<B> bucketBuilder, BucketsAggregator.ResultBuilderForVariable<B> resultBuilder) throws IOException Build 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 interfaceReleasable- 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 IOException Description 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
-
checkRealMemoryCBForInternalBucket
protected final void checkRealMemoryCBForInternalBucket()This method should be called whenever a new bucket object is created. It will check the real memory circuit breaker in a sampling fashion. SeeAggregatorBase.checkRealMemoryCB(String)
-