gpt4 book ai didi

hadoop - Elasticsearch:数周的聚合 min_doc_count 不起作用

转载 作者:可可西里 更新时间:2023-11-01 14:47:05 25 4
gpt4 key购买 nike

我对 interval=weekmin_doc_count=0

进行了以下聚合
{
"aggs": {
"scores_by_date": {
"date_histogram": {
"field": "date",
"format": "yyyy-MM-dd",
"interval": "week",
"min_doc_count": 0
}
}
}

和日期过滤器从 Jan-01-2015Feb-23-2015

{
"range": {
"document.date": {
"from": "2015-01-01",
"to": "2015-02-23"
}
}
}

我预计 Elasticsearch 会填满七个星期,即使是空的并返回桶,但最终只有一个项目在里面

{
"aggregations": {
"scores_by_date": {
"buckets": [
{
"key_as_string": "2015-01-05",
"key": 1420416000000,
"doc_count": 5
}
]
}
}
}

Elasticsearch 版本:1.4.0

我的聚合有什么问题,或者我如何使用 Elasticsearch 来填补缺失的周数?

最佳答案

您可以尝试指定扩展边界(在 histogram aggregations 的官方文档页面上有讨论此功能的文档)。这些文档中最相关的部分是:

With extended_bounds setting, you now can "force" the histogram aggregation to start building buckets on a specific min values and also keep on building buckets up to a max value (even if there are no documents anymore). Using extended_bounds only makes sense when min_doc_count is 0 (the empty buckets will never be returned if min_doc_count is greater than 0).

因此您的聚合可能必须看起来像这样以强制 ES 返回该范围内的空桶:

{
"aggs": {
"scores_by_date": {
"date_histogram": {
"field": "date",
"format": "yyyy-MM-dd",
"interval": "week",
"min_doc_count": 0,
"extended_bounds" : {
"min" : "2015-01-01",
"max" : "2015-02-23"
}
}
}
}

关于hadoop - Elasticsearch:数周的聚合 min_doc_count 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28675181/

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