一尘不染

Elasticsearch映射中的自定义日期格式

elasticsearch

我正在尝试使用日期格式索引数据Tue May 14 17:06:01 PDT 2013。如Elasticsearch
日期格式文档中所述,我需要使用自定义日期格式。我指的是DateTimeFormat文档,并且各自的格式是E M d H:m:s z Y

我能够创建映射,但是当我尝试索引数据时会给我错误。

对应:

{
  "tweet": {
    "properties": {
      "user": {
        "type": "string",
        "index": "not_analyzed"
      },
      "message": {
        "type": "string",
        "null_value": "na"
      },
      "postDate": {
        "type": "date",
        "format": "E M d H:m:s z Y"
      },
      "priority": {
        "type": "integer"
      },
      "rank": {
        "type": "float"
      }
    }
  }
}

索引文件:

curl -XPUT 'http://localhost:9200/tweets/tweet/1' -d '{
        "user" : "kimchy",
        "message" : "This is a tweet!",
        "postDate" : "Tue May 14 17:06:01 PDT 2013",
        "priority" : 4,
        "rank" : 12.3
}'

错误:-

{"error":"MapperParsingException[failed to parse [postDate]]; 
nested: MapperParsingException[failed to parse date field [Tue May 14 17:06:01 PDT 2013],
tried both date format [E M d H:m:s z Y], and timestamp number with locale []];
nested: IllegalArgumentException[Invalid format: \"Tue May 14 17:06:01 PDT 2013\"
is malformed at \"May 14 17:06:01 PDT 2013\"]; ","status":400}

有什么建议吗?


阅读 635

收藏
2020-06-22

共1个答案

一尘不染

本月使用三个“ M”。引用API文档

月:3岁或以上,请使用文字,否则请使用数字。

因此,您提供的输入的正确映射应为:

    "postDate": {
      "type": "date",
      "format": "E MMM d H:m:s z Y"
    }
2020-06-22