# Date sorting and dateOptionalTime format (default one) problem

**URL:** <https://discuss.elastic.co/t/date-sorting-and-dateoptionaltime-format-default-one-problem/8261>\
**Category:** Elasticsearch\
**Created:** [June 29, 2012, 2:23pm UTC](https://discuss.elastic.co/t/date-sorting-and-dateoptionaltime-format-default-one-problem/8261 "2012-06-29T14:23:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Benoit](https://avatars.discourse-cdn.com/v4/letter/b/5daacb/32.png) [@Benoit](https://discuss.elastic.co/u/Benoit)\
**Post date:** [June 29, 2012, 2:23pm UTC](https://discuss.elastic.co/t/date-sorting-and-dateoptionaltime-format-default-one-problem/8261/1 "2012-06-29T14:23:44Z")

</div>

Hi,

dateOptionalTime accept both YYYYMMDD and YYYY-MM-DD format which is ok  
with ISO format.  
But the primer seems not internally converted to date.

I have added '"dynamic" : false' to the mapping to be sure the problem  
doesn’t come from there.  
The order of documents insertion doesn't change the behavior.

Thanks to try the following gist: [https://gist.github.com/3018231](https://gist.github.com/3018231)  
The sort and facet query show the problem.

Benoît

---

<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:** [June 29, 2012, 6:27pm UTC](https://discuss.elastic.co/t/date-sorting-and-dateoptionaltime-format-default-one-problem/8261/2 "2012-06-29T18:27:24Z")

</div>

The YYYYMMDD format is not supported, the dateOptionalTime parser seems to  
be too lenient and allows to parse it, but the wrong result. Need to figure  
out how to force it to fail... . You can explicitly set the format yourself  
to make sure it will fail.

On Fri, Jun 29, 2012 at 4:23 PM, Benoît [benoit.intrw@gmail.com](mailto:benoit.intrw@gmail.com) wrote:

> Hi,
> 
> dateOptionalTime accept both YYYYMMDD and YYYY-MM-DD format which is ok  
> with ISO format.  
> But the primer seems not internally converted to date.
> 
> I have added '"dynamic" : false' to the mapping to be sure the problem  
> doesn’t come from there.  
> The order of documents insertion doesn't change the behavior.
> 
> Thanks to try the following gist: [Elasticsearch: Date sorting and dateOptionalTime format (default one) problem. · GitHub](https://gist.github.com/3018231)  
> The sort and facet query show the problem.
> 
> Benoît

---

<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, 3:22am UTC](https://discuss.elastic.co/t/date-sorting-and-dateoptionaltime-format-default-one-problem/8261/3 "2017-07-06T03:22:00Z")

</div>


