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:
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
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interface
BucketsAggregator.BucketBuilderForFixedCount<B>
protected static interface
BucketsAggregator.BucketBuilderForVariable<B>
protected static interface
BucketsAggregator.ResultBuilderForVariable<B>
protected static interface
BucketsAggregator.SingleBucketResultBuilder
Nested classes/interfaces inherited from class org.elasticsearch.search.aggregations.Aggregator
Aggregator.BucketComparator, Aggregator.Parser, Aggregator.SubAggCollectionMode
-
Field Summary
Fields inherited from class org.elasticsearch.search.aggregations.AggregatorBase
collectableSubAggregators, context, DEFAULT_WEIGHT, name, parent, subAggregators
-
Constructor Summary
Constructors Constructor Description BucketsAggregator(java.lang.String name, AggregatorFactories factories, SearchContext context, Aggregator parent, CardinalityUpperBound bucketCardinality, java.util.Map<java.lang.String,java.lang.Object> metadata)
-
Method Summary
Modifier and Type Method Description protected void
beforeBuildingBuckets(long[] ordsToCollect)
Hook to allow taking an action before building buckets.Aggregator.BucketComparator
bucketComparator(java.lang.String key, SortOrder order)
Builds a comparator that compares two buckets aggregated by this Aggregator.int
bucketDocCount(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, java.util.function.Function<java.util.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 oflong
keyed buckets.protected <B> void
buildSubAggsForAllBuckets(B[][] buckets, java.util.function.ToLongFunction<B> bucketToOrd, java.util.function.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> void
buildSubAggsForBuckets(B[] buckets, java.util.function.ToLongFunction<B> bucketToOrd, java.util.function.BiConsumer<B,InternalAggregations> setAggs)
Build the sub aggregation results for a list of buckets and set them on the buckets.void
close()
Called upon release of the aggregator.void
collectBucket(LeafBucketCollector subCollector, int doc, long bucketOrd)
Utility method to collect the given doc in the given bucket (identified by the bucket ordinal)void
collectExistingBucket(LeafBucketCollector subCollector, int doc, long bucketOrd)
Same ascollectBucket(LeafBucketCollector, int, long)
, but doesn't check if the docCounts needs to be re-sized.static boolean
descendsFromGlobalAggregator(Aggregator parent)
IntArray
getDocCounts()
void
grow(long maxBucketOrd)
Ensure there are at leastmaxBucketOrd
buckets available.void
incrementBucketDocCount(long bucketOrd, int inc)
Utility method to increment the doc counts of the given bucket (identified by the bucket ordinal)long
maxBucketOrd()
Return an upper bound of the maximum bucket ordinal seen so far.void
mergeBuckets(long[] mergeMap, long newNumBuckets)
This only tidies up doc counts.Aggregator
resolveSortPath(AggregationPath.PathElement next, java.util.Iterator<AggregationPath.PathElement> path)
Resolve a sort path to the target.Methods inherited from class org.elasticsearch.search.aggregations.AggregatorBase
addRequestCircuitBreakerBytes, buildEmptySubAggregations, context, doClose, doPostCollection, doPreCollection, getLeafCollector, getLeafCollector, metadata, name, parent, pointReaderIfAvailable, postCollection, preCollection, preGetSubLeafCollectors, scoreMode, subAggregator, subAggregators, toString
Methods inherited from class org.elasticsearch.search.aggregations.Aggregator
buildAggregations, buildEmptyAggregation, buildTopLevel, collectDebugInfo, resolveSortPathOnValidAgg
-
Constructor Details
-
BucketsAggregator
public BucketsAggregator(java.lang.String name, AggregatorFactories factories, SearchContext context, Aggregator parent, CardinalityUpperBound bucketCardinality, java.util.Map<java.lang.String,java.lang.Object> metadata) throws java.io.IOException- Throws:
java.io.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 leastmaxBucketOrd
buckets available. -
collectBucket
public final void collectBucket(LeafBucketCollector subCollector, int doc, long bucketOrd) throws java.io.IOExceptionUtility 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.IOExceptionSame ascollectBucket(LeafBucketCollector, int, long)
, but doesn't check if the docCounts needs to be re-sized.- Throws:
java.io.IOException
-
mergeBuckets
public final void mergeBuckets(long[] mergeMap, long newNumBuckets)This only tidies up doc counts. CallMergingBucketsDeferringCollector.mergeBuckets(long[])
to merge the actual ordinals and doc ID deltas. Refer to that method for documentation about the merge map. -
getDocCounts
-
incrementBucketDocCount
public final void incrementBucketDocCount(long bucketOrd, int inc)Utility method to increment the doc counts of the given bucket (identified by the bucket ordinal) -
bucketDocCount
public final int bucketDocCount(long bucketOrd)Utility method to return the number of documents that fell in the given bucket (identified by the bucket ordinal) -
beforeBuildingBuckets
protected void beforeBuildingBuckets(long[] ordsToCollect) throws java.io.IOExceptionHook to allow taking an action before building buckets.- Throws:
java.io.IOException
-
buildSubAggsForBuckets
protected final InternalAggregations[] buildSubAggsForBuckets(long[] bucketOrdsToCollect) throws java.io.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:
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.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:
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.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:
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.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:
java.io.IOException
-
buildAggregationsForSingleBucket
protected final InternalAggregation[] buildAggregationsForSingleBucket(long[] owningBucketOrds, BucketsAggregator.SingleBucketResultBuilder resultBuilder) throws java.io.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:
java.io.IOException
-
buildAggregationsForVariableBuckets
protected final <B> InternalAggregation[] buildAggregationsForVariableBuckets(long[] owningBucketOrds, LongKeyedBucketOrds bucketOrds, BucketsAggregator.BucketBuilderForVariable<B> bucketBuilder, BucketsAggregator.ResultBuilderForVariable<B> resultBuilder) throws java.io.IOExceptionBuild aggregation results for an aggregator with a varying number oflong
keyed buckets.- Parameters:
owningBucketOrds
- owning bucket ordinals for which to build the resultsbucketOrds
- 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 interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in interfaceReleasable
- Overrides:
close
in classAggregatorBase
-
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 classAggregator
-
bucketComparator
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 classAggregator
-
descendsFromGlobalAggregator
-