# Mapping multiple date formats

**URL:** <https://discuss.elastic.co/t/mapping-multiple-date-formats/4490>\
**Category:** Elasticsearch\
**Created:** [May 27, 2011, 8:29pm UTC](https://discuss.elastic.co/t/mapping-multiple-date-formats/4490 "2011-05-27T20:29:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![searchersteve](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/searchersteve/32/3008_2.png) [@searchersteve](https://discuss.elastic.co/u/searchersteve)\
**Post date:** [May 27, 2011, 8:29pm UTC](https://discuss.elastic.co/t/mapping-multiple-date-formats/4490/1 "2011-05-27T20:29:38Z")

</div>

In creating a \_mapping, I am using the || operator to allow for indexing multiple formats in a date field. I am following procedures described [here](http://www.elasticsearch.org/guide/reference/mapping/date-format.html) in the guide. My problem: The order in which I list the formats matters. For example...

If I specify:

```
"post_date" : {"type" : "date","format" : "yyyy-MM-dd HH:mm:ss||MM/dd/yyyy||MM-dd-yyyy"}

```

Then I can successfully index:

```
"post_date" : "2009-11-15 14:12:12"

```

If I specify:

```
 "post_date" : {"type" : "date","format" : "MM/dd/yyyy||MM-dd-yyyy||yyyy-MM-dd HH:mm:ss"}

```

Then indexing the same post\_date fails.

The full code example is at: [https://gist.github.com/24bee84dbeae5359583f](https://gist.github.com/24bee84dbeae5359583f)

I do see in the documentation that the first format listed has a different functionality. It says, "The first format will also act as the one that converts back from milliseconds to a string representation." But I don't see why this would cause the behavior described above.

Thoughts?

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [May 28, 2011, 10:24am UTC](https://discuss.elastic.co/t/mapping-multiple-date-formats/4490/2 "2011-05-28T10:24:51Z")

</div>

Thats a bug in ES (thanks for the simple repro), created an issue or it: [Mapping - Date Format: 3 or more custom date formats fail using '||' delimiter · Issue #977 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/977) and pushed a fix to 0.16 and master branches.

On Friday, May 27, 2011 at 11:29 PM, searchersteve wrote:

> In creating a \_mapping, I am using the || operator to allow for indexing  
> multiple formats in a date field. I am following procedures described  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/date-format.html) here  
> in the guide. My problem: If I allow for too many formats, parsing fails.  
> For example...
> 
> If I specify:
> 
> "post\_date" : {"type" : "date","format" : "MM-dd-yyyy||yyyy-MM-dd  
> HH:mm:ss"}
> 
> Then I can successfully index:
> 
> "post\_date" : "2009-11-15 14:12:12"
> 
> If I specify:
> 
> "post\_date" : {"type" : "date","format" :  
> "MM/dd/yyyy||MM-dd-yyyy||yyyy-MM-dd HH:mm:ss"}
> 
> Then indexing the same post\_date fails.
> 
> The full code example is at: [ElasticSearch date formats · GitHub](https://gist.github.com/24bee84dbeae5359583f)  
> [ElasticSearch date formats · GitHub](https://gist.github.com/24bee84dbeae5359583f)
> 
> It makes sense that at some point, a parser will get confused if you throw  
> too many allowed formats at it. You end up with potential ambiguity that the  
> parser cannot resolve. But I can't see the ambiguity in this case.
> 
> Thoughts?
> 
> --  
> View this message in context: [http://elasticsearch-users.115913.n3.nabble.com/Mapping-multiple-date-formats-tp2994323p2994323.html](http://elasticsearch-users.115913.n3.nabble.com/Mapping-multiple-date-formats-tp2994323p2994323.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com) ([http://Nabble.com](http://Nabble.com)).

---

<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, 4:05am UTC](https://discuss.elastic.co/t/mapping-multiple-date-formats/4490/3 "2017-07-06T04:05:09Z")

</div>


