弹性搜索如何按字母顺序按组值排序?

时间:2017-02-26 06:21:07

标签: elasticsearch elasticsearch-1.6.0

我对分组结果有下列查询,我想要添加到此查询中的是按字母顺序对分组值进行排序。

GET promote_kmp/audit_table/_search
{
  "aggs":{
    "group_by_table_name":{
       "terms":{
         "field":"table_name",
         "size":1000000000
       }
    }
  }
}

2 个答案:

答案 0 :(得分:2)

只需添加order setting

即可
POST promote_kmp/audit_table/_search
{
  "aggs":{
    "group_by_table_name":{
       "terms":{
         "field":"table_name",
         "size":1000000000,
         "order": { "_term": "asc" }          <---- add this
       }
    }
  }
}

答案 1 :(得分:1)

只需添加:

GET promote_kmp/audit_table/_search
{
  "aggs":{
     "group_by_table_name":{
        "terms":{
           "field":"table_name",
           "size":1000000000,
           "order": {
             "_term": "asc"
           }
         }
       }
     }
   }