Class TopBucketBuilder<B extends InternalMultiBucketAggregation.InternalBucket>
BucketOrder.-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionabstract voidadd(DelayedBucket<B> bucket) Add a bucket if it is competitive.build()Return the most competitive buckets sorted by the comparator.static <B extends InternalMultiBucketAggregation.InternalBucket>
TopBucketBuilder<B> build(int size, BucketOrder order, Consumer<DelayedBucket<B>> nonCompetitive, BiFunction<List<B>, AggregationReduceContext, B> reduce, AggregationReduceContext reduceContext) Create aTopBucketBuilderto build a list of the top buckets.
-
Field Details
-
nonCompetitive
protected final Consumer<DelayedBucket<B extends InternalMultiBucketAggregation.InternalBucket>> nonCompetitive
-
-
Method Details
-
build
public static <B extends InternalMultiBucketAggregation.InternalBucket> TopBucketBuilder<B> build(int size, BucketOrder order, Consumer<DelayedBucket<B>> nonCompetitive, BiFunction<List<B>, AggregationReduceContext, B> reduce, AggregationReduceContext reduceContext) Create aTopBucketBuilderto build a list of the top buckets.If there are few required results we use a
TopBucketBuilder.PriorityQueueTopBucketBuilderwhich is simpler and when the priority queue is full but allocatessize + 1slots in an array. If there are many required results we prefer aTopBucketBuilder.BufferingTopBucketBuilderwhich doesn't preallocate and is faster for the firstsizeresults. But it's a little slower when the priority queue is full.It's important for this not to preallocate a bunch of memory when
sizeis very very large because this backs the reduction of thetermsaggregation and folks often set thesizeof that to something quite large. The choice in the paragraph above handles this case.- Parameters:
size- the requested size of the listorder- the sort order of the bucketsnonCompetitive- called with non-competitive bucketsreduce- function to reduce a list of bucketsreduceContext- the reduce context
-
add
Add a bucket if it is competitive. If there isn't space but the bucket is competitive then this will drop the least competitive bucket to make room for the new bucket.Instead of operating on complete buckets we this operates on a wrapper containing what we need to merge the buckets called
DelayedBucket. We can evaluate some common sort criteria directly on the DelayedBuckets so we only need to merge exactly the sub-buckets we need. -
build
Return the most competitive buckets sorted by the comparator.
-