我正在尝试elasticsearch 2.3中的日期范围聚合。我想将它们汇总为过去30天,过去7天和今天。因此,我的聚合查询的一部分如下:
"range": {
"ranges": [
{
"from": "now-30d/d",
"to": "now/d"
},
{
"from": "now-7d/d",
"to": "now/d"
},
{
"from": "now/d",
"to": "now+1d/d"
}
],
"format": "yyyy-MM-dd"
}
这将导致以下存储桶:
"buckets": [
{
"key": "2017-01-23-2017-02-22",
"from": 1485129600000,
"from_as_string": "2017-01-23",
"to": 1487721600000,
"to_as_string": "2017-02-22",
"doc_count": 6
},
{
"key": "2017-02-15-2017-02-22",
"from": 1487116800000,
"from_as_string": "2017-02-15",
"to": 1487721600000,
"to_as_string": "2017-02-22",
"doc_count": 6
},
{
"key": "2017-02-22-2017-02-23",
"from": 1487721600000,
"from_as_string": "2017-02-22",
"to": 1487808000000,
"to_as_string": "2017-02-23",
"doc_count": 0
}
]
在安装了elasticsearch的机器上,date
命令的输出如下:
Tue Feb 21 23:01:59 PST 2017
从存储桶中可以看到,elasticsearch函数now
的计算结果是2017-02-22
,但我希望它是2017-02-21
。这里我漏掉了什么?
提前谢谢。
发布于 2017-02-23 14:25:44
再次阅读文档后,我了解到now
函数使用的是协调世界时,而不是安装了elasticsearch的机器的时区。因此,可以看到这种行为。这已在最新版本的elasticsearch中修复,其中可以在日期范围聚合中指定time_zone
属性。可在此处跟踪此问题- https://github.com/elastic/elasticsearch/issues/10130
https://stackoverflow.com/questions/42384779
复制相似问题