Secondary sort on aggregation buckets

(Ivan Brusic) #1

I started investigating switching from facets to aggregations in order to
have access to some of the new features aggregations offer.

One of them is the ability to sort on a sub-aggregation metric, which is
working well, but the buckets that are tied come back in a random order.
Since it is not possible to sort the buckets of a stats aggregation (the
sub aggregation), there is no explicit secondary order. Is there any way to
setup the sub aggregations to be returned in order? Default order (count)
is fine.

The gist of the aggregations is

"aggs": {
"myagg": {
"terms": {
"field": "myfield",
"order": {
"maxotherfield": "desc"
"size": 100
"aggs": {
"maxotherfield": {
"max": {
"field": "someotherfield"

Haven't looked at the code much, but there is definitely no direct support
for secondary sorts.



You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To view this discussion on the web visit
For more options, visit

(system) #2