使用 nohup 或 disown 如果你要让某个进程运行在后台。

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
已邀请:

guoyanbiao520

赞同来自: codersun

兄弟,你都没有bcd,cde他怎么会知道这俩值呢~~~~~

yongde - 90后IT男

赞同来自:

业务层做下处理

要回复问题请先登录注册