# Geo\_distance sorting on geo\_point in nested document

**URL:** https://discuss.elastic.co/t/geo-distance-sorting-on-geo-point-in-nested-document/12042
**Category:** Elasticsearch
**Created:** [May 20, 2013, 10:39pm UTC](https://discuss.elastic.co/t/geo-distance-sorting-on-geo-point-in-nested-document/12042 "2013-05-20T22:39:24Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![loren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/loren/32/44942_2.png) [@loren](https://discuss.elastic.co/u/loren)
#### Post date: [May 20, 2013, 10:39pm UTC](https://discuss.elastic.co/t/geo-distance-sorting-on-geo-point-in-nested-document/12042/1 "2013-05-20T22:39:24Z")

</div>

I am running into a problem with geo\_distance sorting on nested documents  
containing geo\_points and I am wondering if I am just going about it  
incorrectly. Here is a simplified version of what I have:

curl -X DELETE [http://localhost:9200/venue](http://localhost:9200/venue)  
curl -X POST [http://localhost:9200/venue](http://localhost:9200/venue) -d '  
{  
"mappings": {  
"venue": {  
"properties": {  
"name": {  
"type": "string"  
},  
"locations": {  
"type": "nested",  
"properties": {  
"geo": {  
"type": "geo\_point"  
},  
"city": {  
"type": "string"  
}  
}  
}  
}  
}  
}  
}  
'

curl -X POST "[http://localhost:9200/venue/venue/](http://localhost:9200/venue/venue/)" -d  
'{"type":"venue","name":"One","locations":[{"city":"Chicago","geo":[40.1,-70.1]}]}'  
curl -X POST "[http://localhost:9200/venue/venue/](http://localhost:9200/venue/venue/)" -d  
'{"type":"venue","name":"Two","locations":[{"city":"New  
York","geo":[10.1,-7.1]},{"city":"Los Angeles","geo":[140.1,-120.1]}]}'  
curl -X POST "[http://localhost:9200/venue/venue/](http://localhost:9200/venue/venue/)" -d  
'{"type":"venue","name":"Three","locations":[{"city":"Canberra","geo":[40.2,-70.2]}]}'  
curl -X POST "[http://localhost:9200/venue/venue/](http://localhost:9200/venue/venue/)" -d  
'{"type":"venue","name":"Four","locations":[{"city":"Atlanta","geo":[5.1,5.1]}]}'

curl -X POST "[http://localhost:9200/venue/\_refresh](http://localhost:9200/venue/_refresh)"

# Filtering works as expected

curl -X GET '[http://localhost:9200/venue/\_search?pretty](http://localhost:9200/venue/_search?pretty)' -d '  
{  
"query": {  
"filtered": {  
"query": {  
"match\_all": {}  
},  
"filter": {  
"nested": {  
"path": "locations",  
"filter": {  
"geo\_distance": {  
"distance": "60km",  
"geo": {  
"lat": -70.00331,  
"lon": 40.0834715  
}  
}  
}  
}  
}  
}  
}  
}  
'

# This does not work as I'd expected. I'm just looking for the venues

closest  
curl -X GET '[http://localhost:9200/venue/\_search?pretty](http://localhost:9200/venue/_search?pretty)' -d '  
{  
"track\_scores": true,  
"query": {  
"match\_all": {}  
},  
"sort": [  
{  
"\_geo\_distance": {  
"locations.geo": [  
5,  
5  
]  
}  
}  
]  
}  
'

#If I remove the 'nested' specification from the mapping, it does work as  
expected:  
curl -X DELETE [http://localhost:9200/venue](http://localhost:9200/venue)  
curl -X POST [http://localhost:9200/venue](http://localhost:9200/venue) -d '  
{  
"mappings": {  
"venue": {  
"properties": {  
"name": {  
"type": "string"  
},  
"locations": {  
"properties": {  
"geo": {  
"type": "geo\_point"  
},  
"city": {  
"type": "string"  
}  
}  
}  
}  
}  
}  
}  
'

Is there something special I need to do to get geo\_distance sorting to work  
with nested documents?

--  
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).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![loren](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/loren/32/44942_2.png) [@loren](https://discuss.elastic.co/u/loren)
#### Post date: [May 31, 2013, 4:38pm UTC](https://discuss.elastic.co/t/geo-distance-sorting-on-geo-point-in-nested-document/12042/2 "2013-05-31T16:38:15Z")

</div>

Fixed  
by [https://github.com/elasticsearch/elasticsearch/commit/db421742f71e40a0b132e20ac6508dfac5c8ab9c](https://github.com/elasticsearch/elasticsearch/commit/db421742f71e40a0b132e20ac6508dfac5c8ab9c)

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).  
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, 2:33am UTC](https://discuss.elastic.co/t/geo-distance-sorting-on-geo-point-in-nested-document/12042/3 "2017-07-06T02:33:32Z")

</div>


