# Using multiple geo\_points per document, return matched geo\_point(s)

**URL:** <https://discuss.elastic.co/t/using-multiple-geo-points-per-document-return-matched-geo-point-s/47796>\
**Category:** Elasticsearch\
**Created:** [April 19, 2016, 1:30pm UTC](https://discuss.elastic.co/t/using-multiple-geo-points-per-document-return-matched-geo-point-s/47796 "2016-04-19T13:30:10Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![japel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/japel/32/9241_2.png) [@japel](https://discuss.elastic.co/u/japel)\
**Post date:** [April 19, 2016, 1:30pm UTC](https://discuss.elastic.co/t/using-multiple-geo-points-per-document-return-matched-geo-point-s/47796/1 "2016-04-19T13:30:10Z")

</div>

I index documents with each an array of geo\_points. I am able to do a distance search returning only those documents with geo\_points within a certain radius of another geo location.  
Is there any way to determine which geo\_points in the array matched my query?  
I'd like to know which matched, so I can e.g. render them in a google maps layer as markers.

---

<div class="post-metadata">

**Author:** ![japel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/japel/32/9241_2.png) [@japel](https://discuss.elastic.co/u/japel)\
**Post date:** [April 25, 2016, 3:57pm UTC](https://discuss.elastic.co/t/using-multiple-geo-points-per-document-return-matched-geo-point-s/47796/2 "2016-04-25T15:57:37Z")

</div>

It seems this cannot be achieved this way. I managed to do it using parent child relationships, so my documents are parents of children with geopoints.  
Doing this, I am able to do a has\_child query on those children, and using inner\_hits I get those children back that matched.

[https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-distance-query.html)  
[https://www.elastic.co/guide/en/elasticsearch/guide/current/parent-child.html](https://www.elastic.co/guide/en/elasticsearch/guide/current/parent-child.html)  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-child-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-has-child-query.html)  
[https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-inner-hits.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-inner-hits.html)

It'd be still interesting if there is a better way of doing this. It seems to me it should be very common use-case and I wonder why I can't find anything on this.

So if someone ever did something similar, I would love to know which approach was used.

---

<div class="post-metadata">

**Author:** ![pickypg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pickypg/32/62409_2.png) [@pickypg](https://discuss.elastic.co/u/pickypg)\
**Post date:** [April 25, 2016, 7:11pm UTC](https://discuss.elastic.co/t/using-multiple-geo-points-per-document-return-matched-geo-point-s/47796/3 "2016-04-25T19:11:40Z")

</div>

I would be wary of using parent/child just to achieve the use case that you are doing here. It may prove easier to just do a client-side validation of geo points versus the radius. There are tons of libraries that will do that check for you, and given a small subset of documents it should be a cheap operation.

There are tons of libraries that enable this kind of behavior and it avoids the overhead that parent/child brings (both to complexity of code and the complexity added to the system).

---

<div class="post-metadata">

**Author:** ![japel](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/japel/32/9241_2.png) [@japel](https://discuss.elastic.co/u/japel)\
**Post date:** [May 4, 2016, 10:55am UTC](https://discuss.elastic.co/t/using-multiple-geo-points-per-document-return-matched-geo-point-s/47796/4 "2016-05-04T10:55:05Z")

</div>

Thank you for your thoughts... I can't foresee how many locations there will be right now... Besides that, I think this is something that the server should do. But you are right on the increased complexity... 😕

---

<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 5, 2017, 10:54pm UTC](https://discuss.elastic.co/t/using-multiple-geo-points-per-document-return-matched-geo-point-s/47796/5 "2017-07-05T22:54:03Z")

</div>


