2017-02-22 75 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