gpt4 book ai didi

elasticsearch - 排除空的子桶 ElasticSearch

转载 作者:行者123 更新时间:2023-12-02 22:16:53 27 4
gpt4 key购买 nike

我写了一个有两个级别的聚合查询:

{
"size": 0,
"aggregations": {
"colors": {
"terms": {
"field": "color"
},
"aggregations": {
"timestamps": {
"date_histogram": {
"field": "timestamp",
"interval": "1m",
"order": {
"_key": "desc"
}
},
"aggregations": {
"timestamps_bucket_filter": {
"bucket_selector": {
"buckets_path": {
"counterts": "_count"
},
"script": {
"lang": "expression",
"script": "counterts == 0"
}
}
}
}
}
}
}
}
}

可以看出,我正在过滤所有仅包含零个文档的子桶(时间戳)。问题是,经过上述过滤后,高级桶(颜色)处有空桶。

例如:

.
.
.
"aggregations": {
"colors": {
"doc_count_error_upper_bound": 12144,
"sum_other_doc_count": 14785757,
"buckets": [
.
.
.,
{
"key": "Yellow", // <<-- this is an empty bucket I would like to exclude
"doc_count": 57223,
"timestamps": {
"buckets": [
// <<-- empty
]
}
},
.
.
.

如何从任何时间戳子桶中排除所有保持为空的颜色桶?

提前致谢!

最佳答案

根据 this page ,您可以指定要包含的存储桶的最小文档数:

     "date_histogram": {
"field": "timestamp",
"interval": "1m",
"min_doc_count" : 1,
"order": {
"_key": "desc"
}
},

关于elasticsearch - 排除空的子桶 ElasticSearch,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38328054/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com