terms聚合时如何将没有数据的分组默认值为0返回,而不是不显示
匿名 | 发布于2021年02月05日 | 阅读数:2090
terms聚合时如何将没有数据的分组默认值为0返回,而不是不显示
请求
{
"query": {
"match_all": {}
},
"size": 0,
"aggs": {
"group": {
"terms": {
"field": "test",
"size": 2
}
}
}
}
返回
{
"took": 20,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 4,
"relation": "eq"
},
"max_score": null,
"hits": []
},
"aggregations": {
"group": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "abc",
"doc_count": 4
}
]
}
}
}
,但是我想要的效果是{
"took": 20,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 4,
"relation": "eq"
},
"max_score": null,
"hits": []
},
"aggregations": {
"group": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "abc",
"doc_count": 4
},
{
"key": "bcd",
"doc_count": 0
},
{
"key": "cde",
"doc_count": 0
}
]
}
}
}
,没有数据的项默认返回0
2 个回复
guoyanbiao520
赞同来自: codersun
yongde - 90后IT男
赞同来自: