2017-02-22 76 views
0

功能我想出来的日期范围聚集elasticsearch 2.3。我想将它们汇总为过去30天,过去7天和今天。因此,我聚合查询的一部分,如下所示:问题与现在elasticsearch

"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 
    } 
    ] 

date命令的在安装elasticsearch机器的输出如下所示:

Tue Feb 21 23:01:59 PST 2017 

由于从桶看出,elasticsearch功能now评估为2017-02-22,但我希望它是2017-02-21。我在这里错过了什么?

在此先感谢。

+1

现在不受time_zone参数的影响(日期必须存储为UTC)。试着改变你的时区为UTC – user3775217

+0

https://discuss.elastic.co/t/several-date-math-questions/27453/4 – user3775217

回答

0

通过文件再次去后,我明白了now函数使用UTC时间不是安装elasticsearch机器的时区。因此看到了这种行为。这已在最新版本的elasticsearch中得到修复,其中time_zone属性可以在日期范围聚合中指定。此问题在此处被跟踪 - https://github.com/elastic/elasticsearch/issues/10130