2017-09-01 19 views
1

我想日期时间2017-02-17T15:02:00在下面的查询来替代now如何用Elasticsearch查询中的具体日期时间替换“now”?

POST /myindex/_search 
{ 
    "size": 0, 
"aggs": { 
    "range": { 
     "date_range": { 
      "field": "Datetime", 
      "ranges": [ 
       { "to": "now-1H/H" }, 
       { "from": "now/H" } 
      ] 
     } 
    } 
} 
} 

如果我直接2017-02-17T15:02:00替代now,则查询失败,错误:

type": "illegal_argument_exception", "reason": "Unrecognized chars at the end of [2017-02-17T15:02:00/H]: [/H]"

此外,如何能我指定了一小时而不是1H?

回答

1

date math doc指出

The expression starts with an anchor date, which can either be now , or a date string ending with || .

这意味着在你的榜样,你必须2017-02-17T15:02:00||

替代now尝试{ "to": "2017-02-17T15:02:00||-1H/H" }

要指定一刻钟,使用分钟符号代替:
{ "to": "2017-02-17T15:02:00||-15m/H" }