Hey,

I am running an aggregation that groups by a terms aggregation and then runs the sum on a field for each bucket. Works of course.

Now on top of that I have a bucket script aggregation running, that is doing a calculation with the doc_count of each bucket and the result of the sum agg.

After this calculation I would like to filter (a minimum threshold of that calculated value) and sort based on that calculated bucket script output.

I do not see how I can sort on pipeline bucket outputs, as the documentation explicitely states, that sorting on the terms bucket agg is only for multi bucket aggs.

Maybe I misread the docs and this is somehow possible (or any other alternative that I am not seeing)? This is on Elasticsearch 8.14.

Thanks in advance!

--Alex