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

**URL:** <https://discuss.elastic.co/t/sorting-by-proximity-nearest-neighbors-in-multi-dimensional-space/2227>\
**Category:** Elasticsearch\
**Created:** [June 9, 2015, 2:43pm UTC](https://discuss.elastic.co/t/sorting-by-proximity-nearest-neighbors-in-multi-dimensional-space/2227 "2015-06-09T14:43:44Z")\
**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 9, 2015, 2:43pm UTC](https://discuss.elastic.co/t/sorting-by-proximity-nearest-neighbors-in-multi-dimensional-space/2227/1 "2015-06-09T14:43:44Z")

</div>

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.

---

<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:08am UTC](https://discuss.elastic.co/t/sorting-by-proximity-nearest-neighbors-in-multi-dimensional-space/2227/2 "2017-07-06T00:08:47Z")

</div>


