I am writing a function which just groupby a string property. For this purpose, I need to select topValues()
as the aggregation type. However, I get all possible buckets, while I just need the first 10 ones. Is it possible to set the max. number of buckets to retrieve?
.topValues(10
) is not working. No configuration possibility available.- I wrote a function to return 1000 values and then, keep just the first 10. This is however really unefficient.
Currently the topValues() aggregation does not support a pre-defined bucket count. Your approach of calculating the top 1000 and then post-filtering is the best option.
For others looking, here's a code snippet for reference:
There is a feature request tracking an enhancement to add this configuration, though I would expect this to be more of a convenience rather than a performance improvement, since to calculate the top N buckets you roughly have to know the sizes of the other buckets (with some obvious room for optimization).