解析日期

时间:2016-03-01 08:53:13

标签: date parsing exception elasticsearch

我收到以下异常:

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

在以下查询中:

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映射为:

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

示例条目是:

{
      "_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"}

1 个答案:

答案 0 :(得分:0)

我最后用milli发送时间,因为这是ES在这个特定情况下愿意接受的唯一格式。

如果有人有任何建议我愿意听取替代方案。

所以这确实有效:

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