在 Elasticsearch 中面临聚合查询问题。问题如下,
我在同一查询中要求两个不同的聚合。第一个是“显示 subject.label 这些特定值的文档计数”,第二个是“显示 subject.label 中 5 个最常见值的文档计数。”
已尝试查询,
POST my_index/search
{
"query": {
"match_all": {}
},
"size": 0,
"aggs": {
"selected": {
"terms": {
"field": "subject.label",
"include": [ "Buddhist art" ],
"order": { "_count": "desc" },
"size": 5
}
},
"subject": {
"terms": {
"field": "subject.label",
"order": { "_count": "desc" },
"size": 5
}
}
}
}
得到以下结果
{
"took" : 5,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 10000,
"relation" : "gte"
},
"max_score" : null,
"hits" : [ ]
},
"aggregations" : {
"userFacets" : {
"doc_count_error_upper_bound" : 0,
"sum_other_doc_count" : 0,
"buckets" : [
{
"key" : "Buddhist art",
"doc_count" : 12
}
]
},
"subject" : {
"doc_count_error_upper_bound" : 11,
"sum_other_doc_count" : 1005,
"buckets" : [
{
"key" : "Architecture",
"doc_count" : 88
},
{
"key" : "Painting",
"doc_count" : 80
},
{
"key" : "Berkeley (Calif.)",
"doc_count" : 25
},
{
"key" : "Buddhist art",
"doc_count" : 11
},
{
"key" : "Church architecture",
"doc_count" : 10
}
]
}
}
}
第一个聚合结果中Buddhist art的值怎么可能是12而第二个聚合结果中却是11?这是对单个索引的单个聚合查询。 (事实上,有 12 个文档的 subject.label 值为“佛教艺术”。)。
(这个例子我取自另一篇文章https://discuss.elastic.co/t/ Different-aggregation-count-for-the-same-value/324566)
谢谢你。
approximate
结果。从您分享的 ES 回复中我可以看到以下内容:
"subject" : {
"doc_count_error_upper_bound" : 11,
"sum_other_doc_count" : 1005,
这意味着为了搜索速度而忽略了一些文档。
即使使用较大的 shard_size 值,术语聚合的 doc_count 值也可能是近似的。因此,术语聚合上的任何子聚合也可能是近似的。
您可以增加shard_size以获得更准确的结果。
sum_other_doc_count 是未成功的文档数量 进入顶部尺寸条款。如果这个值大于0,你可以 确保术语 agg 必须扔掉一些桶,要么是因为 它们不适合协调节点的尺寸或者不适合 到数据节点上的 shard_size 中。 https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html#terms-agg-doc-count-error