Sorting by proximity (nearest neighbors) in multi-dimensional space


(Dan Weitzenfeld) #1

Each of my documents is associated with multiple points in space. In each of my queries, I pass in a single point, and I need all of my queries to be sorted by minimum proximity to this point.
So I have a field called 'locations' that holds all the points associated with each document, and I sort like so:

    {
        "_geo_distance": {
            "locations": [lon, lat],
            "order": "asc",
            "unit": "mi",
            "distance_type": "plane"
        }
    }

I'd like to replicate this functionality, but with more than 2 dimensions. So one document's 'locations' field might be:

'locations': [[1,3,4], [2,5,6], [0, 0, 1]]

Questions:

  1. I found some discussion on github about adding a dimension to geo_point; will this just change the cap from 2 dimensions to 3? When will this be released? Will geohashes support 3-d points?
  2. Is there a way to get my desired sort using scripting? If each document had one location, it would be trivial, and I am considering changing my schema accordingly. But I'm wondering if it's possible to get the same result without changing my schema.

Thanks.


(system) #2