# Custom date format in elasticsearch mapping

**URL:** <https://discuss.elastic.co/t/custom-date-format-in-elasticsearch-mapping/20240>\
**Category:** Elasticsearch\
**Created:** [October 14, 2014, 12:23pm UTC](https://discuss.elastic.co/t/custom-date-format-in-elasticsearch-mapping/20240 "2014-10-14T12:23:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![roopednra](https://avatars.discourse-cdn.com/v4/letter/r/e19adc/32.png) [@roopednra](https://discuss.elastic.co/u/roopednra)\
**Post date:** [October 14, 2014, 12:23pm UTC](https://discuss.elastic.co/t/custom-date-format-in-elasticsearch-mapping/20240/1 "2014-10-14T12:23:30Z")

</div>

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](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](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](mailto: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](https://groups.google.com/d/msgid/elasticsearch/eb4187c8-ab4a-4ab7-8018-7be3777f3124%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![roopednra](https://avatars.discourse-cdn.com/v4/letter/r/e19adc/32.png) [@roopednra](https://discuss.elastic.co/u/roopednra)\
**Post date:** [October 16, 2014, 6:06am UTC](https://discuss.elastic.co/t/custom-date-format-in-elasticsearch-mapping/20240/2 "2014-10-16T06:06:17Z")

</div>

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](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](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](mailto: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](https://groups.google.com/d/msgid/elasticsearch/c361c787-c75d-4e35-a772-c8b22bb21ae0%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 12:55am UTC](https://discuss.elastic.co/t/custom-date-format-in-elasticsearch-mapping/20240/3 "2017-07-06T00:55:52Z")

</div>


