简体   繁体   English

解析日期上的弹性搜索异常

[英]Elastic search exception on parsing date

I am getting the following exception: 我收到以下异常:

ElasticsearchParseException[failed to parse date field [2016-02-20T22:00:00.000Z], tried both date format [dateOptionalTime], and timestamp number]; nested: IllegalArgumentException[Invalid format: \"2016-02-20T22:00:00.000Z\"]

On the following query: 在以下查询中:

curl -XGET https://xxxx.us-east-1.es.amazonaws.com/yyy/zzz/_search?pretty=true -d '
{
    "size": 0,
    "query": {
        "filtered": {
            "filter": {
                "bool": {
                    "must": [
                        {
                            "range": {
                                "event_timestamp": {
                                    "gte": "‌2016-02-20T22:00:00.000Z",
                                    "lte": "‌2016-02-27T22:00:00.000Z"
                                }
                            }
                        }
                    ]
                }
            }
        }
    }
}
'

event_timestamp is mapped as: event_timestamp映射为:

"event_timestamp":{"type":"date","format":"dateOptionalTime"}

And a sample entry is: 样本条目为:

{
      "_index" : "yyy",
      "_type" : "zzz",
      "_id" : "abcde",
      "_score" : 1.0,
      "_source":{"event":"xxx","client_timestamp":"1456347863865","event_timestamp":"2016-02-24T21:04:23.495Z","partitionKey":"xxx"}

I ended up sending the time in milli as that's the only format ES is willing to accept in this specific scenario as it seems. 我最终以毫秒为单位发送时间,因为这似乎是ES愿意在这种特定情况下接受的唯一格式。

If anyone has any suggestions I'm open to hear alternatives. 如果有人有任何建议,我很乐意听取其他选择。

So this did work: 所以这确实起作用:

curl -XGET https://xxxx.us-east-1.es.amazonaws.com/yyy/zzz/_search?pretty=true -d '
{
    "size": 0,
    "query": {
        "filtered": {
            "filter": {
                "bool": {
                    "must": [
                        {
                            "range": {
                                "event_timestamp": {
                                     "gte": 1456005600000,
                                     "lte": 1456610400000
                                }
                            }
                        }
                    ]
                }
            }
        }
    }
}
'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM