# How to get all documents with geo\_point within 2-3 polygons(geo\_shape) with single index?

**URL:** https://discuss.elastic.co/t/how-to-get-all-documents-with-geo-point-within-2-3-polygons-geo-shape-with-single-index/151594
**Category:** Elasticsearch
**Created:** [October 9, 2018, 9:34am UTC](https://discuss.elastic.co/t/how-to-get-all-documents-with-geo-point-within-2-3-polygons-geo-shape-with-single-index/151594 "2018-10-09T09:34:17Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Mayur\_Patel1](https://avatars.discourse-cdn.com/v4/letter/m/b782af/32.png) [@Mayur\_Patel1](https://discuss.elastic.co/u/Mayur_Patel1)
#### Post date: [October 9, 2018, 9:34am UTC](https://discuss.elastic.co/t/how-to-get-all-documents-with-geo-point-within-2-3-polygons-geo-shape-with-single-index/151594/1 "2018-10-09T09:34:18Z")

</div>

Hi,

I have one index say "all\_geo\_docs" which contains all documents and all have a geo\_shape field with type geo\_shape and geo\_point field with type geo\_point.

Now I have one field named 'org\_type' in all docs with value 'type\_poly' or 'type\_point'. If a value is 'type\_poly' that means that doc is Polygon or else if the value is 'type\_point' that means that doc is Point.

Now from the same index, I want to get all documents(with type geo\_point) for which point of the doc is within 2-3 polygons(which exist in the same index with type geo\_shape). I have name and id of that 2-3 polygons. How can I write geo\_query for the same?

In short, I want to get all geo\_point documents for which point lies within specific 2-3 polygons?

Thanks in advance.

---

<div class="post-metadata">

### Author: ![Ignacio\_Vera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ignacio_vera/32/36674_2.png) [@Ignacio\_Vera](https://discuss.elastic.co/u/Ignacio_Vera)
#### Post date: [October 12, 2018, 10:25am UTC](https://discuss.elastic.co/t/how-to-get-all-documents-with-geo-point-within-2-3-polygons-geo-shape-with-single-index/151594/2 "2018-10-12T10:25:32Z")

</div>

I am trying to understand the question and I am not sure what you mean with `2-3 polygons`. Could you elaborate a bit more what do you mean?

It is always a good practice to provide an example (mappings, data and queries) that shows the expected behaviour.

---

<div class="post-metadata">

### Author: ![Mayur\_Patel1](https://avatars.discourse-cdn.com/v4/letter/m/b782af/32.png) [@Mayur\_Patel1](https://discuss.elastic.co/u/Mayur_Patel1)
#### Post date: [October 22, 2018, 1:42pm UTC](https://discuss.elastic.co/t/how-to-get-all-documents-with-geo-point-within-2-3-polygons-geo-shape-with-single-index/151594/3 "2018-10-22T13:42:38Z")

</div>

Hi,

Thanks for the reply.

So I have only one index with 2 fields with type geo\_point and geo\_shape. To be clear, geo\_shapes are the polygon geo-json of the boundary on google map for region. So let's say I have 10 geo\_shapes. So what I want in the result is find all geo\_points which fall within 2-3 of the geo\_shapes.

Solution or say patch I used for the same: I was trying to use the geo\_shape query with geo\_point data type so this is not possible as geo\_share query won't work with geo\_point. So what I did is I have indexed geo\_point as a geo\_shape type and it's working as expected.

It's working perfectly and I don't know if it's a proper way or patch only.

Thanks,  
Mayur

---

<div class="post-metadata">

### Author: ![Ignacio\_Vera](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ignacio_vera/32/36674_2.png) [@Ignacio\_Vera](https://discuss.elastic.co/u/Ignacio_Vera)
#### Post date: [October 25, 2018, 9:25am UTC](https://discuss.elastic.co/t/how-to-get-all-documents-with-geo-point-within-2-3-polygons-geo-shape-with-single-index/151594/4 "2018-10-25T09:25:05Z")

</div>

You are right, you cannot use geo\_shape query with a geo point field. You have to use GeoPolygon query but cannot be mixed up with geo\_shape fields.

I think it is a proper solution in this case.

---

<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: [November 22, 2018, 9:25am UTC](https://discuss.elastic.co/t/how-to-get-all-documents-with-geo-point-within-2-3-polygons-geo-shape-with-single-index/151594/5 "2018-11-22T09:25:05Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
