1

I have bellow query to group result, what i want to add to this query is to sort grouped values alphabetically.

GET promote_kmp/audit_table/_search
{
  "aggs":{
    "group_by_table_name":{
       "terms":{
         "field":"table_name",
         "size":1000000000
       }
    }
  }
}
jones
  • 1,423
  • 3
  • 35
  • 76

2 Answers2

2

Simply add the order setting:

POST promote_kmp/audit_table/_search
{
  "aggs":{
    "group_by_table_name":{
       "terms":{
         "field":"table_name",
         "size":1000000000,
         "order": { "_term": "asc" }          <---- add this
       }
    }
  }
}
Val
  • 207,596
  • 13
  • 358
  • 360
1

Just add this:

GET promote_kmp/audit_table/_search
{
  "aggs":{
     "group_by_table_name":{
        "terms":{
           "field":"table_name",
           "size":1000000000,
           "order": {
             "_term": "asc"
           }
         }
       }
     }
   }
Mobasher Fasihy
  • 1,021
  • 2
  • 9
  • 17