Returning geo_distance on all children in a nested field

(Dan Weitzenfeld) #1

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.

(system) #2