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
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-date-format.html
document I need to use custom date format. I refer to DateTimeFormat
http://joda-time.sourceforge.net/api-release/org/joda/time/format/DateTimeFormat.html
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? Which date format I should use here?

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/eb4187c8-ab4a-4ab7-8018-7be3777f3124%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Resolved:

Corrected version date format is :

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

On Tuesday, 14 October 2014 17:53:30 UTC+5:30, Roopendra Vishwakarma wrote:

I am trying to index data with date format Tue May 14 17:06:01 PDT 2013.
As described in Elasticsearch Date Format
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-date-format.html
document I need to use custom date format. I refer to DateTimeFormat
http://joda-time.sourceforge.net/api-release/org/joda/time/format/DateTimeFormat.html
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? Which date format I should use here?

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/c361c787-c75d-4e35-a772-c8b22bb21ae0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

1 Like