# Native script sorting geoPoints

**URL:** <https://discuss.elastic.co/t/native-script-sorting-geopoints/21326>\
**Category:** Elasticsearch\
**Created:** [December 19, 2014, 8:18am UTC](https://discuss.elastic.co/t/native-script-sorting-geopoints/21326 "2014-12-19T08:18:01Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ronny\_Deter](https://avatars.discourse-cdn.com/v4/letter/r/d2c977/32.png) [@Ronny\_Deter](https://discuss.elastic.co/u/Ronny_Deter)\
**Post date:** [December 19, 2014, 8:18am UTC](https://discuss.elastic.co/t/native-script-sorting-geopoints/21326/1 "2014-12-19T08:18:01Z")

</div>

Hi i have an nested object

"root" {  
....  
"userLocations": {  
"type" : "nested",  
"include\_in\_parent" : true,  
"properties": {  
"id": {  
"type": "integer"  
},  
"location": {  
"properties": {  
"city": {  
"type": "string"  
},  
"zipCode": {  
"type": "string"  
},  
"countryIsoCode": {  
"type": "string"  
},  
"longitude": {  
"type": "float"  
},  
"latitude": {  
"type": "float"  
},  
"geoPoint" : {  
"type": "geo\_point"  
}  
}  
}  
}  
}

i have to one root document n userLocations as nested objects.  
I can serach with an native script for the closest distance to an point.  
But i can not filter the userLocations.id for the closest distance.  
Because userLocations.id is sorted by numeric.

Here is my script:

/\*\*

- Created by rdeter on 18.12.14.  
\*/  
public class NestedLocation extends AbstractLongSearchScript {  
double distance = 100000;  
double lat;  
double lon;  
long id;

--  
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/46a872e7-cb9e-4230-b15f-74b035890a28%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/46a872e7-cb9e-4230-b15f-74b035890a28%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 12:42am UTC](https://discuss.elastic.co/t/native-script-sorting-geopoints/21326/2 "2017-07-06T00:42:46Z")

</div>


