Top hits Aggregation 较为常用的统计。获取到每组前n条数据。相当于sql 中 group by 后取出前n条
例子:取100组,每组只要第一条。为了简便没用order和_source,请自行测试他们。
GET test_index/_search?search_type=count
{
"query": {
"match_all": {}
},
"aggs": {
"all_interests": {
"terms": {
"field": "department_id",
"size": 100
},
"aggs": {
"top_tag_hits": {
"top_hits": {
"size": 1
}
}
}
}
}
}~~~
网友评论