【发布时间】:2022-01-04 05:21:50
【问题描述】:
查询
GET /_search
{
"size" : 0,
"query" : {
"ids" : {
"types" : [ ],
"values" : [ "someId1", "someId2", "someId3" ... ]
}
},
"aggregations" : {
"how_to_merge" : {
"terms" : {
"field" : "country",
"size" : 50
}
}
}
}
结果
{
...
"aggregations": {
"how_to_merge": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "KR",
"doc_count": 90
},
{
"key": "JP",
"doc_count": 83
},
{
"key": "US",
"doc_count": 50
},
{
"key": "BE",
"doc_count": 9
}
]
}
}
}
我想合并“KR”和“JP”和“US”
并将键名更改为“NEW_RESULT”
所以结果一定是这样的:
{
...
"aggregations": {
"how_to_merge": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "NEW_RESULT",
"doc_count": 223
},
{
"key": "BE",
"doc_count": 9
}
]
}
}
}
在elasticsearch查询中可以吗?
我不能使用客户端解决方案,因为实体太多,检索所有实体和合并对于我的应用程序来说可能太慢了。
感谢您的帮助和cmets!
【问题讨论】:
标签: elasticsearch elasticsearch-aggregation elasticsearch-dsl