2017-02-26 149 views
1

我有波紋管查詢分組結果,我想要添加到此查詢是按字母順序對分組值進行排序。彈性搜索如何按字母順序按組值排序?

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

回答

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

只需補充一點:

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