# Issues with timestamp sorting

**URL:** https://discuss.elastic.co/t/issues-with-timestamp-sorting/15166
**Category:** Elasticsearch
**Created:** [January 9, 2014, 10:22am UTC](https://discuss.elastic.co/t/issues-with-timestamp-sorting/15166 "2014-01-09T10:22:27Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Chetana](https://avatars.discourse-cdn.com/v4/letter/c/dbc845/32.png) [@Chetana](https://discuss.elastic.co/u/Chetana)
#### Post date: [January 9, 2014, 10:22am UTC](https://discuss.elastic.co/t/issues-with-timestamp-sorting/15166/1 "2014-01-09T10:22:27Z")

</div>

I have created a timestamp field (not be confused with \_timestamp) and want  
to sort timestamp field in descending order. But the result contains some  
records out of order.

Mapping and the sorting criteria look like :  
"timestamp":{"type"  
:"date","format":"dateOptionalTime","include\_in\_all":false}

SearchRequestBuilder.addSort("timestamp", SortOrder.DESC);

The result I get is :

2013-12-26T09:14:09.617Z  
,2013-12-26T12:01:07.389Z,2013-12-26T12:00:20.126Z,2013-12-26T11:59:15.594Z,2013-12-26T11:58:00.083Z,2013-12-26T11:55:52.372Z

Is it because of dateOptionalTime format or am I missing something?

Thanks

--  
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/6616a823-4421-4dbe-a440-a14fdce07e18%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6616a823-4421-4dbe-a440-a14fdce07e18%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)
#### Post date: [January 14, 2014, 11:06am UTC](https://discuss.elastic.co/t/issues-with-timestamp-sorting/15166/2 "2014-01-14T11:06:32Z")

</div>

Hey,

can you create a reproducible gist for this (it is hard to help with so few  
information)? Also, are you sure the mapping is applied correctly?

--Alex

On Thu, Jan 9, 2014 at 11:22 AM, Chetana [ambha.career@gmail.com](mailto:ambha.career@gmail.com) wrote:

> I have created a timestamp field (not be confused with \_timestamp) and  
> want to sort timestamp field in descending order. But the result contains  
> some records out of order.
> 
> Mapping and the sorting criteria look like :  
> "timestamp":{"type"  
> :"date","format":"dateOptionalTime","include\_in\_all":false}
> 
> SearchRequestBuilder.addSort("timestamp", SortOrder.DESC);
> 
> The result I get is :
> 
> 2013-12-26T09:14:09.617Z  
> ,2013-12-26T12:01:07.389Z,2013-12-26T12:00:20.126Z,2013-12-26T11:59:15.594Z,2013-12-26T11:58:00.083Z,2013-12-26T11:55:52.372Z
> 
> Is it because of dateOptionalTime format or am I missing something?
> 
> Thanks
> 
> --  
> 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/6616a823-4421-4dbe-a440-a14fdce07e18%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/6616a823-4421-4dbe-a440-a14fdce07e18%40googlegroups.com)  
> .  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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/CAGCwEM8HQEFN\_DR8Y5EDiDKsiJJ1aHsuwhKwEQbiVGBA63FHPg%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAGCwEM8HQEFN_DR8Y5EDiDKsiJJ1aHsuwhKwEQbiVGBA63FHPg%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 1:56am UTC](https://discuss.elastic.co/t/issues-with-timestamp-sorting/15166/3 "2017-07-06T01:56:59Z")

</div>


