【问题标题】:Elastic search exception on parsing date解析日期的弹性搜索异常
【发布时间】:2016-03-01 08:53:12
【问题描述】:

我收到以下异常:

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

【问题讨论】:

  • dateOptionalTime 是您的自定义格式吗??
  • 其实我没有指定,当我为基于时间的索引选择这个字段作为所谓的“时间字段名称”时 kibana 输入的内容

标签: date parsing exception elasticsearch


【解决方案1】:

我最终以毫秒为单位发送时间,因为这是 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
                                }
                            }
                        }
                    ]
                }
            }
        }
    }
}
'

【讨论】:

    猜你喜欢
    • 2021-05-26
    • 1970-01-01
    • 1970-01-01
    • 2012-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多