# Returning geo\_distance on all children in a nested field

**URL:** <https://discuss.elastic.co/t/returning-geo-distance-on-all-children-in-a-nested-field/1869>\
**Category:** Elasticsearch\
**Created:** [June 3, 2015, 8:37pm UTC](https://discuss.elastic.co/t/returning-geo-distance-on-all-children-in-a-nested-field/1869 "2015-06-03T20:37:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Weitzenfeld](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/weitzenfeld/32/578_2.png) [@Weitzenfeld](https://discuss.elastic.co/u/Weitzenfeld)\
**Post date:** [June 3, 2015, 8:37pm UTC](https://discuss.elastic.co/t/returning-geo-distance-on-all-children-in-a-nested-field/1869/1 "2015-06-03T20:37:19Z")

</div>

My documents have a nested field. Each child in the nested field has a 'location' property of type 'geo\_point.'  
My first hurdle was sorting based on the closest child to my query origin, but I figured out two different ways to do that:

1. Extracting the geo\_points into a property at the document root level, e.g. 'locations': [[175, 25], [122, 36], ...]
2. Sorting on the nested children using 'nested\_path'

However, in both of these solutions, the query only returns the distance to the _nearest_ point. I'd like to return distance to _every_ point, while sorting on the minimum distance.

I have a sense that I should use script\_fields, but I can't find anything in the documentation about how to apply a script field to every child of a nested field.

---

<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:09am UTC](https://discuss.elastic.co/t/returning-geo-distance-on-all-children-in-a-nested-field/1869/2 "2017-07-06T00:09:47Z")

</div>


