# Sorting problems

**URL:** <https://discuss.elastic.co/t/sorting-problems/15598>\
**Category:** Elasticsearch\
**Created:** [February 4, 2014, 6:07pm UTC](https://discuss.elastic.co/t/sorting-problems/15598 "2014-02-04T18:07:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![damian\_noseda](https://avatars.discourse-cdn.com/v4/letter/d/ecccb3/32.png) [@damian\_noseda](https://discuss.elastic.co/u/damian_noseda)\
**Post date:** [February 4, 2014, 6:07pm UTC](https://discuss.elastic.co/t/sorting-problems/15598/1 "2014-02-04T18:07:43Z")

</div>

Hello

I'm having problems with sorting. I want to get the latest data (with the  
biggest date\_created).

So I curl like this:

curl -vsX GET [myelastic.com/notifications/notification/\_search](http://myelastic.com/notifications/notification/_search) -d '{

"query": {  
"bool": {  
"must": [  
{  
"term": {  
"type": "config\_withdraw"  
}  
}  
],  
"must\_not": [],  
"should": []  
}  
},  
"sort": [  
{  
"date\_created": "desc"  
}  
],  
"size": 1  
}'|python -mjson.tool

RESULT:

{  
"\_shards": {  
"failed": 0,  
"successful": 10,  
"total": 10  
},  
"hits": {  
"hits": [  
{  
"\_id": "a3Rks7DNTYWGDRZzVg5g8Q",  
"\_index": "notifications",  
"\_score": null,  
"\_source": {  
"date\_created": "2024-02-01T13:49:52.454-04:00",  
"expiration\_date": "2024-02-01T13:49:52.452-04:00",  
"level": null,  
"model": {  
"user\_id": 80843387  
},  
"reference\_id": null,  
"status": "new",  
"type": "config\_withdraw",  
"user\_id": "80843387"  
},  
"\_type": "notification",  
"sort": [  
1706809792454  
]  
}  
],  
"max\_score": null,  
"total": 10533937  
},  
"timed\_out": false,  
"took": 163  
}

But this is not the latest data becouse in another search I get a bigger date\_created:

curl -vsX GET [myelastic.com/notifications/notification/\_search](http://myelastic.com/notifications/notification/_search) -d '{  
"query": {  
"bool": {  
"must": [  
{  
"term": {  
"user\_id": "153423413"  
}  
}  
],  
"must\_not": [],  
"should": []  
}  
},  
"sort": [  
{  
"date\_created": "desc"  
}  
],  
"size": 1  
}'|python -mjson.tool

RESULT:  
{  
"\_shards": {  
"failed": 0,  
"successful": 10,  
"total": 10  
},  
"hits": {  
"hits": [  
{  
"\_id": "PfWSkIDxSk2ou62Yiqbudw",  
"\_index": "notifications",  
"\_score": null,  
"\_source": {  
"date\_created": "2014-02-03T13:48:11.524-04:00",  
"expiration\_date": "2024-02-01T13:48:11.524-04:00",  
"level": null,  
"model": {  
"user\_id": 153423413  
},  
"reference\_id": null,  
"status": "new",  
"type": "config\_withdraw",  
"user\_id": "153423413"  
},  
"\_type": "notification",  
"sort": [  
1391449691524  
]  
}  
],  
"max\_score": null,  
"total": 2  
},  
"timed\_out": false,  
"took": 36  
}

So I don't know what is the problem, maybe you can give me some pointer.

BTW this is the mapping of the type

curl -vsX GET [myelastic.com/notifications/notification/\_mapping](http://myelastic.com/notifications/notification/_mapping)

RESULT:

{  
"notification": {  
"properties": {  
"date\_created": {  
"format": "dateOptionalTime",  
"type": "date"  
},  
"expiration\_date": {  
"format": "dateOptionalTime",  
"type": "date"  
},  
"id": {  
"type": "string"  
},  
"model": {  
"properties": {  
"bank": {  
"type": "string"  
},  
"new\_status": {  
"type": "string"  
},  
"status": {  
"type": "string"  
},  
"user\_id": {  
"type": "long"  
}  
}  
},  
"reference\_id": {  
"type": "long"  
},  
"status": {  
"type": "string"  
},  
"type": {  
"type": "string"  
},  
"user\_id": {  
"type": "string"  
}  
}  
}  
}

--  
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/30763a38-3b05-4c22-a910-f24b0f8e35d4%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/30763a38-3b05-4c22-a910-f24b0f8e35d4%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:** ![jsbonline2006](https://avatars.discourse-cdn.com/v4/letter/j/85f322/32.png) [@jsbonline2006](https://discuss.elastic.co/u/jsbonline2006)\
**Post date:** [February 5, 2014, 3:39am UTC](https://discuss.elastic.co/t/sorting-problems/15598/2 "2014-02-05T03:39:24Z")

</div>

Hi,

Can you try following syntax for sorting the date value?  
"sort": [  
{  
"date\_created": {  
"order": "desc"  
}  
}  
]

Let me know if this solves your problem.

I was using this syntax succesfully for integer value

Regards,  
Jayesh Bhoyar  
[http://www.linkedin.com/in/jayeshbhoyar](http://www.linkedin.com/in/jayeshbhoyar)

--  
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/a0dbad62-9561-48ca-bc1e-eb96f1a72c2a%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/a0dbad62-9561-48ca-bc1e-eb96f1a72c2a%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:** ![damian\_noseda](https://avatars.discourse-cdn.com/v4/letter/d/ecccb3/32.png) [@damian\_noseda](https://discuss.elastic.co/u/damian_noseda)\
**Post date:** [February 5, 2014, 11:14am UTC](https://discuss.elastic.co/t/sorting-problems/15598/3 "2014-02-05T11:14:42Z")

</div>

Hi, thanks for the answer. It does the same thing. It gaves me data 2 days  
old

On Wednesday, February 5, 2014 12:39:24 AM UTC-3, Jayesh Bhoyar wrote:

> Hi,
> 
> Can you try following syntax for sorting the date value?  
> "sort": [  
> {  
> "date\_created": {  
> "order": "desc"  
> }  
> }  
> ]
> 
> Let me know if this solves your problem.
> 
> I was using this syntax succesfully for integer value
> 
> Regards,  
> Jayesh Bhoyar  
> [http://www.linkedin.com/in/jayeshbhoyar](http://www.linkedin.com/in/jayeshbhoyar)

--  
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/8358bfc4-6939-4419-8927-aa296fa42745%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/8358bfc4-6939-4419-8927-aa296fa42745%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:** ![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:52am UTC](https://discuss.elastic.co/t/sorting-problems/15598/4 "2017-07-06T01:52:26Z")

</div>


