# TimeStamp based sorting is not working in ES

**URL:** https://discuss.elastic.co/t/timestamp-based-sorting-is-not-working-in-es/10094
**Category:** Elasticsearch
**Created:** [December 17, 2012, 3:17pm UTC](https://discuss.elastic.co/t/timestamp-based-sorting-is-not-working-in-es/10094 "2012-12-17T15:17:46Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Prab](https://avatars.discourse-cdn.com/v4/letter/p/d2c977/32.png) [@Prab](https://discuss.elastic.co/u/Prab)
#### Post date: [December 17, 2012, 3:17pm UTC](https://discuss.elastic.co/t/timestamp-based-sorting-is-not-working-in-es/10094/1 "2012-12-17T15:17:46Z")

</div>

Hi All,

I have a field timeStamp (which is not be confused \_timestamp), where i  
store date\_time format date (yyyy-MM-dd'T'HH:mm:ss.SSSZ). I have pushed a  
couple of documents with different timestamp.  
[http://localhost:9200/\_search?Sort=timeStamp:desc&from=0&size=10](http://localhost:9200/_search?Sort=timeStamp:desc&from=0&size=10)

Tried to query it using above URI. But it seem to be not in sorted order as  
expected.  
mapping looks like below,

· "timeStamp": {

- "type": "date",
- \*"format": "date\_time" \*

what i am looking for is to sort the timestamp value in desc/asc  
format...is there anything wrong which i am trying? Thanks for the help.

-Prab

--

---

<div class="post-metadata">

### Author: ![radu\_gheorghe](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/radu_gheorghe/32/556_2.png) [@radu\_gheorghe](https://discuss.elastic.co/u/radu_gheorghe)
#### Post date: [December 17, 2012, 5:23pm UTC](https://discuss.elastic.co/t/timestamp-based-sorting-is-not-working-in-es/10094/2 "2012-12-17T17:23:02Z")

</div>

Hello,

I'm not sure how you can do it just with the URL, but this should work:

curl localhost:9200/\_search?pretty=true -d '{"sort":{"timeStamp": "desc"}}'

## Best regards, Radu

[http://sematext.com/](http://sematext.com/) -- Elasticsearch -- Solr -- Lucene

On Mon, Dec 17, 2012 at 5:17 PM, Prab [itsmeprabhakar@gmail.com](mailto:itsmeprabhakar@gmail.com) wrote:

> Hi All,
> 
> I have a field timeStamp (which is not be confused \_timestamp), where i  
> store date\_time format date (yyyy-MM-dd'T'HH:mm:ss.SSSZ). I have pushed a  
> couple of documents with different timestamp.  
> [http://localhost:9200/\_search?Sort=timeStamp:desc&from=0&size=10](http://localhost:9200/_search?Sort=timeStamp:desc&from=0&size=10)
> 
> Tried to query it using above URI. But it seem to be not in sorted order  
> as expected.  
> mapping looks like below,
> 
> · "timeStamp": {
> 
> - "type": "date",
> - \*"format": "date\_time" \*
> 
> what i am looking for is to sort the timestamp value in desc/asc  
> format...is there anything wrong which i am trying? Thanks for the help.
> 
> -Prab
> 
> --

--

---

<div class="post-metadata">

### Author: ![Prab](https://avatars.discourse-cdn.com/v4/letter/p/d2c977/32.png) [@Prab](https://discuss.elastic.co/u/Prab)
#### Post date: [December 18, 2012, 4:36am UTC](https://discuss.elastic.co/t/timestamp-based-sorting-is-not-working-in-es/10094/3 "2012-12-18T04:36:32Z")

</div>

Hi Radu,

Thanks for replying...it was an Usage error. I figured it out.  
[http://localhost:9200/\_search?Sort=timeStamp:desc&from=0&size=10](http://localhost:9200/_search?Sort=timeStamp:desc&from=0&size=10)

S in sort should be lower case 😃

Thanks  
Prab

On Monday, December 17, 2012 10:53:02 PM UTC+5:30, Radu Gheorghe wrote:

> Hello,
> 
> I'm not sure how you can do it just with the URL, but this should work:
> 
> curl localhost:9200/\_search?pretty=true -d '{"sort":{"timeStamp": "desc"}}'
> 
> ## Best regards, Radu
> 
> [http://sematext.com/](http://sematext.com/) -- Elasticsearch -- Solr -- Lucene
> 
> On Mon, Dec 17, 2012 at 5:17 PM, Prab \<[itsmepr...@gmail.com](mailto:itsmepr...@gmail.com) \<javascript:\>\>wrote:
> 
> > Hi All,
> > 
> > I have a field timeStamp (which is not be confused \_timestamp), where i  
> > store date\_time format date (yyyy-MM-dd'T'HH:mm:ss.SSSZ). I have pushed  
> > a couple of documents with different timestamp.  
> > [http://localhost:9200/\_search?Sort=timeStamp:desc&from=0&size=10](http://localhost:9200/_search?Sort=timeStamp:desc&from=0&size=10)
> > 
> > Tried to query it using above URI. But it seem to be not in sorted order  
> > as expected.  
> > mapping looks like below,
> > 
> > · "timeStamp": {
> > 
> > - "type": "date",
> > - \*"format": "date\_time" \*
> > 
> > what i am looking for is to sort the timestamp value in desc/asc  
> > format...is there anything wrong which i am trying? Thanks for the help.
> > 
> > -Prab
> > 
> > --

--

---

<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, 2:59am UTC](https://discuss.elastic.co/t/timestamp-based-sorting-is-not-working-in-es/10094/4 "2017-07-06T02:59:29Z")

</div>


