工作中遇到需要统计分组数量的查询,记录一下
GET /fy_roomel/_search
{
"size": 0,
"aggs": {
"groupNAME": {
"terms": {
"field": "district.keyword"
}
},
"count":{
"cardinality": {
"field": "district.keyword"
}
}
}
}
ps: 按区域分组, 统计有几个区域文章来源:https://www.toymoban.com/news/detail-728572.html
结果文章来源地址https://www.toymoban.com/news/detail-728572.html
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 145,
"relation" : "eq"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"groupNAME" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "包河区",
"doc_count" : 87
},
{
"key" : "瑶海区",
"doc_count" : 29
},
{
"key" : "津南区",
"doc_count" : 26
},
{
"key" : "蜀山区",
"doc_count" : 3
}
]
},
"count" : {
"value" : 4
}
}
}
到了这里,关于ES统计分组后的分组数量的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!