Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom date format in elasticsearch mapping

I am trying to index data with date format Tue May 14 17:06:01 PDT 2013. As described in Elasticsearch Date Format document I need to use custom date format. I refer to DateTimeFormat document and respective format is E M d H:m:s z Y.

I am able to create mapping but when I am trying to index data its giving me error.

Mapping:-

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

Index Document:-

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:-

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

Any Suggestion?

like image 307
Roopendra Avatar asked Oct 14 '14 12:10

Roopendra


People also ask

How do I change the date format in Kibana?

Advanced Settingsedit. Advanced Settings control the behavior of Kibana. For example, you can change the format used to display dates, specify the default data view, and set the precision for displayed decimal values. Open the main menu, then click Stack Management > Advanced Settings.


1 Answers

For Month use three 'M's. Quote from the API docs:

Month: 3 or over, use text, otherwise use number.

So the correct mapping for the input you provided should be:

    "postDate": {
      "type": "date",
      "format": "E MMM d H:m:s z Y"
    }
like image 74
Andrei Stefan Avatar answered Sep 20 '22 11:09

Andrei Stefan