elasticsearch mapping中的自定义日期格式

Roo*_*dra 6 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"
      }
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

索引文件: -

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
}'
Run Code Online (Sandbox Code Playgroud)

错误:-

{"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}
Run Code Online (Sandbox Code Playgroud)

有什么建议吗?

And*_*fan 7

月份使用三个'M'.来自API文档的引用:

月份:3或以上,使用文字,否则使用数字.

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

    "postDate": {
      "type": "date",
      "format": "E MMM d H:m:s z Y"
    }
Run Code Online (Sandbox Code Playgroud)