进行简单的术语聚合搜索将满足您的需求:
(
mydata您的字段名称在哪里)
curl -XGET 'http://localhost:9200/test/data/_search?search_type=count&pretty' -d '{ "query": { "match_all" : {} }, "aggs" : { "mydata_agg" : { "terms": {"field" : "mydata"} } }}'将返回:
{ "took" : 3, "timed_out" : false, "_shards" : { "total" : 5, "successful" : 5, "failed" : 0 }, "hits" : { "total" : 3, "max_score" : 0.0, "hits" : [ ] }, "aggregations" : { "mydata_agg" : { "doc_count_error_upper_bound" : 0, "sum_other_doc_count" : 0, "buckets" : [ { "key" : "aaa", "doc_count" : 3 }, { "key" : "fff", "doc_count" : 3 }, { "key" : "bbb", "doc_count" : 2 }, { "key" : "ccc", "doc_count" : 1 }, { "key" : "ddd", "doc_count" : 1 }, { "key" : "eee", "doc_count" : 1 }, { "key" : "hhh", "doc_count" : 1 }, { "key" : "mmm", "doc_count" : 1 }, { "key" : "xxx", "doc_count" : 1 } ] } }}


