# Geo-shape query within

**URL:** <https://discuss.elastic.co/t/geo-shape-query-within/198851>\
**Category:** Elasticsearch\
**Created:** [September 10, 2019, 8:48am UTC](https://discuss.elastic.co/t/geo-shape-query-within/198851 "2019-09-10T08:48:00Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ohoroyoi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ohoroyoi/32/46820_2.png) [@ohoroyoi](https://discuss.elastic.co/u/ohoroyoi)\
**Post date:** [September 10, 2019, 8:48am UTC](https://discuss.elastic.co/t/geo-shape-query-within/198851/1 "2019-09-10T08:48:00Z")

</div>

by this document ([https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-shape-query.html#\_spatial\_relations](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-geo-shape-query.html#_spatial_relations)), I made query like this,

"filter":{  
"geo\_shape":{  
"boundaries":{  
"shape": {  
"type": "envelope",  
"coordinates" : [[126.9243621826172, 37.580228767905275],[127.10941314697267, 37.44406286652748]]  
},  
"relation": "within"  
}  
}  
},

but there is 2 problems.

\< 1 \>  
The within filter gets only the regions that are entirely contained within.  
I would also like to bring an area that contains only a few parts of the current map.

\< 2 \>  
I think it's the same problem as above. If the envelop coordinates of the map do not contain a region, elasticsearch does not return the region.

How can I handle this? Is it possible to use multiple condition within and contains?

---

<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:** [September 10, 2019, 9:18am UTC](https://discuss.elastic.co/t/geo-shape-query-within/198851/2 "2019-09-10T09:18:15Z")

</div>

Not sure if I understand your questions:

What do you mean with few parts? Either you just need an intersect query or you are referring to shapes that are composed of multiple components (e.g multi-polygons) and you just want to match if at least one of those components is within.

Could you clarify?

---

<div class="post-metadata">

**Author:** ![ohoroyoi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ohoroyoi/32/46820_2.png) [@ohoroyoi](https://discuss.elastic.co/u/ohoroyoi)\
**Post date:** [September 10, 2019, 9:42am UTC](https://discuss.elastic.co/t/geo-shape-query-within/198851/3 "2019-09-10T09:42:16Z")

</div>

Using "INTERSECTS" instead of "within" solved all the problems. Sorry for the ambiguous english.

---

<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:** [September 10, 2019, 12:38pm UTC](https://discuss.elastic.co/t/geo-shape-query-within/198851/4 "2019-09-10T12:38:18Z")

</div>

No problem! In addition `INTERSECTS` is the best performing query so good it is enough 🙂

---

<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:** [October 8, 2019, 12:38pm UTC](https://discuss.elastic.co/t/geo-shape-query-within/198851/5 "2019-10-08T12:38:18Z")

</div>

Closed on October 8, 2019, 12:38pm UTC

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