【发布时间】:2021-07-27 01:00:19
【问题描述】:
试图找到一种方法来获取聚合方面的存储桶计数,其中每个存储桶中至少包含两个文档。
能够获取存储桶,并保持足够大的大小以获取所有存储桶,但我真的很想知道如何获取存储桶总数:
"aggregations": {
"by_universalId": {
"terms": {
"size": 10,
"field": "universalId",
"min_doc_count": 2,
"order": [
{
"_count": "desc"
},
{
"_key": "asc"
}
]
}
}
}
This GitHub 线程说,桶选择器是获取计数的正确方法,但无法找到方法。任何帮助表示赞赏,谢谢。
编辑1: 这是索引数据的样子:
{"id":"1", "universalId": "a"}
{"id":"2", "universalId": "a"}
{"id":"3", "universalId": "b"}
{"id":"4", "universalId": "b"}
{"id":"5", "universalId": "c"}
{"id":"6", "universalId": "c"}
{"id":"7", "universalId": "d"}
{"id":"8", "universalId": "d"}
{"id":"9", "universalId": "e"}
{"id":"10", "universalId": "e"}
{"id":"11", "universalId": "f"}
{"id":"12", "universalId": "f"}
{"id":"13", "universalId": "f"}
{"id":"14", "universalId": "g"}
{"id":"15", "universalId": "g"}
{"id":"16", "universalId": "g"}
{"id":"17", "universalId": "g"}
{"id":"18", "universalId": "h"}
{"id":"19", "universalId": "i"}
{"id":"20", "universalId": "j"}
当我运行这个查询时,我得到的计数是 5,而不是 7:
{
"aggregations": {
"by_universalId": {
"terms": {
"size": 5,
"field": "universalId",
"min_doc_count": 2,
"order": [
{
"_count": "desc"
},
{
"_key": "asc"
}
]
}
},
"bucketcount": {
"stats_bucket": {
"buckets_path": "by_universalId._count"
}
}
}
}
这是我得到的:
"aggregations" : {
"by_universalId" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 4,
"buckets" : [
{
"key" : "g",
"doc_count" : 4
},
{
"key" : "f",
"doc_count" : 3
},
{
"key" : "a",
"doc_count" : 2
},
{
"key" : "b",
"doc_count" : 2
},
{
"key" : "c",
"doc_count" : 2
}
]
},
"bucketcount" : {
"count" : 5,
"min" : 2.0,
"max" : 4.0,
"avg" : 2.6,
"sum" : 13.0
}
}
如果我将大小更改为 10,那么我会得到正确的计数,即 7。
无论我在聚合方面传递的大小如何,我都希望计数为 7。
Elasticsearch 版本详情:
"version" : {
"number" : "7.9.2",
"build_flavor" : "default",
"build_type" : "deb",
【问题讨论】:
-
您能否借助示例解释一下您的用例。如果您可以分享一些示例索引数据和预期的搜索结果,那就太好了
-
我试图找到一个实体的重复项。如果两个文档具有相同的universalId,它们将被视为重复。现在我需要拉起至少有一个重复的实体的数量。类似于谷歌在安卓手机中显示的重复联系人。我将尝试创建示例索引数据和预期结果并更新帖子。
标签: elasticsearch elasticsearch-aggregation