# Can't get sorting working on date and geo\_location

**URL:** <https://discuss.elastic.co/t/cant-get-sorting-working-on-date-and-geo-location/4572>\
**Category:** Elasticsearch\
**Created:** [June 8, 2011, 10:43am UTC](https://discuss.elastic.co/t/cant-get-sorting-working-on-date-and-geo-location/4572 "2011-06-08T10:43:31Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![xrado](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xrado/32/3208_2.png) [@xrado](https://discuss.elastic.co/u/xrado)\
**Post date:** [June 8, 2011, 10:43am UTC](https://discuss.elastic.co/t/cant-get-sorting-working-on-date-and-geo-location/4572/1 "2011-06-08T10:43:31Z")

</div>

this is my mapping  
"test" : {  
"properties" : {  
"model" : {  
"index" : "not\_analyzed",  
"type" : "string"  
},  
"expires" : {  
"null\_value" : "-1",  
"format" : "yyyy-MM-dd HH:mm:ss",  
"type" : "date"  
},  
"location" : {  
"type" : "geo\_point"  
},  
"subject" : {  
"type" : "string"  
},  
"description" : {  
"type" : "string"  
},  
"class" : {  
"index" : "not\_analyzed",  
"type" : "string"  
},  
"date" : {  
"format" : "yyyy-MM-dd HH:mm:ss",  
"type" : "date"  
},  
"cid" : {  
"index" : "not\_analyzed",  
"type" : "string"  
},  
"country" : {  
"index" : "not\_analyzed",  
"type" : "string"  
}  
}  
}

sorting by \_id works, but by date and expired I get the same results with asc and desc,  
same with \_geo\_distance sort on location

any idea what I'm doing wrong?

---

<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 8, 2011, 11:02am UTC](https://discuss.elastic.co/t/cant-get-sorting-working-on-date-and-geo-location/4572/2 "2011-06-08T11:02:08Z")

</div>

gist a recreation.

On Wednesday, June 8, 2011 at 1:43 PM, xrado wrote:

> this is my mapping  
> "test" : {  
> "properties" : {  
> "model" : {  
> "index" : "not\_analyzed",  
> "type" : "string"  
> },  
> "expires" : {  
> "null\_value" : "-1",  
> "format" : "yyyy-MM-dd HH:mm:ss",  
> "type" : "date"  
> },  
> "location" : {  
> "type" : "geo\_point"  
> },  
> "subject" : {  
> "type" : "string"  
> },  
> "description" : {  
> "type" : "string"  
> },  
> "class" : {  
> "index" : "not\_analyzed",  
> "type" : "string"  
> },  
> "date" : {  
> "format" : "yyyy-MM-dd HH:mm:ss",  
> "type" : "date"  
> },  
> "cid" : {  
> "index" : "not\_analyzed",  
> "type" : "string"  
> },  
> "country" : {  
> "index" : "not\_analyzed",  
> "type" : "string"  
> }  
> }  
> }
> 
> sorting by \_id works, but by date and expired I get the same results with  
> asc and desc,  
> same with \_geo\_distance sort on location
> 
> any idea what I'm doing wrong?
> 
> --  
> View this message in context: [http://elasticsearch-users.115913.n3.nabble.com/can-t-get-sorting-working-on-date-and-geo-location-tp3038561p3038561.html](http://elasticsearch-users.115913.n3.nabble.com/can-t-get-sorting-working-on-date-and-geo-location-tp3038561p3038561.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:** ![xrado](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xrado/32/3208_2.png) [@xrado](https://discuss.elastic.co/u/xrado)\
**Post date:** [June 8, 2011, 11:48am UTC](https://discuss.elastic.co/t/cant-get-sorting-working-on-date-and-geo-location/4572/3 "2011-06-08T11:48:51Z")

</div>

date sorting [https://gist.github.com/1014273](https://gist.github.com/1014273)

(geo\_distance started working)

---

<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 8, 2011, 1:23pm UTC](https://discuss.elastic.co/t/cant-get-sorting-working-on-date-and-geo-location/4572/4 "2011-06-08T13:23:16Z")

</div>

Whats not working exactly in your gist? Things seem to work well for me, but you did not say what does not work... 🙂

On Wednesday, June 8, 2011 at 2:48 PM, xrado wrote:

> date sorting [elasticsearch date sort · GitHub](https://gist.github.com/1014273)
> 
> (geo\_distance started working)
> 
> --  
> View this message in context: [http://elasticsearch-users.115913.n3.nabble.com/can-t-get-sorting-working-on-date-and-geo-location-tp3038561p3038727.html](http://elasticsearch-users.115913.n3.nabble.com/can-t-get-sorting-working-on-date-and-geo-location-tp3038561p3038727.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:** ![xrado](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xrado/32/3208_2.png) [@xrado](https://discuss.elastic.co/u/xrado)\
**Post date:** [June 8, 2011, 6:15pm UTC](https://discuss.elastic.co/t/cant-get-sorting-working-on-date-and-geo-location/4572/5 "2011-06-08T18:15:33Z")

</div>

try switching sorting order on date ("sort":{"date":"asc"}) or expires ( "sort":{"expires":"asc") asc/desc,  
not sorting, returns the same result [https://gist.github.com/1014273](https://gist.github.com/1014273)

---

<div class="post-metadata">

**Author:** ![thnguyen](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/thnguyen/32/3207_2.png) [@thnguyen](https://discuss.elastic.co/u/thnguyen)\
**Post date:** [June 8, 2011, 6:30pm UTC](https://discuss.elastic.co/t/cant-get-sorting-working-on-date-and-geo-location/4572/6 "2011-06-08T18:30:37Z")

</div>

Sorry just testing if I can reply to posts.

---

<div class="post-metadata">

**Author:** ![Ludovic\_Levesque](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ludovic_levesque/32/3031_2.png) [@Ludovic\_Levesque](https://discuss.elastic.co/u/Ludovic_Levesque)\
**Post date:** [June 8, 2011, 7:32pm UTC](https://discuss.elastic.co/t/cant-get-sorting-working-on-date-and-geo-location/4572/7 "2011-06-08T19:32:27Z")

</div>

Hi,

I just tested on a 0.16.2 cluster, and for dates asc/desc, results are  
the same, but it's normal, date values are the same in both docs  
"2011-06-08 10:30:09", sort value: 1307529009000

For expires asc/desc, I have correct results, see  
[elasticsearch date sort · GitHub](https://gist.github.com/1014273#comments) and sort values: -1 and  
1307701809000

Ludo

On Wed, Jun 8, 2011 at 8:15 PM, xrado [radovan.lozej@gmail.com](mailto:radovan.lozej@gmail.com) wrote:

> try switching sorting order on date ("sort":{"date":"asc"}) or expires (  
> "sort":{"expires":"asc") asc/desc,  
> not sorting, returns the same result [elasticsearch date sort · GitHub](https://gist.github.com/1014273)
> 
> --  
> View this message in context: [http://elasticsearch-users.115913.n3.nabble.com/can-t-get-sorting-working-on-date-and-geo-location-tp3038561p3040193.html](http://elasticsearch-users.115913.n3.nabble.com/can-t-get-sorting-working-on-date-and-geo-location-tp3038561p3040193.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

**Author:** ![xrado](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xrado/32/3208_2.png) [@xrado](https://discuss.elastic.co/u/xrado)\
**Post date:** [June 8, 2011, 8:33pm UTC](https://discuss.elastic.co/t/cant-get-sorting-working-on-date-and-geo-location/4572/8 "2011-06-08T20:33:23Z")

</div>

i guess then is my messy data, need to look closer, thx to all for now

---

<div class="post-metadata">

**Author:** ![fashionalwallet](https://avatars.discourse-cdn.com/v4/letter/f/839c29/32.png) [@fashionalwallet](https://discuss.elastic.co/u/fashionalwallet)\
**Post date:** [June 9, 2011, 9:05am UTC](https://discuss.elastic.co/t/cant-get-sorting-working-on-date-and-geo-location/4572/9 "2011-06-09T09:05:31Z")

</div>

- deleted -

---

<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:04am UTC](https://discuss.elastic.co/t/cant-get-sorting-working-on-date-and-geo-location/4572/10 "2017-07-06T04:04:21Z")

</div>


