# Problems with geo\_shape support

**URL:** https://discuss.elastic.co/t/problems-with-geo-shape-support/10207
**Category:** Elasticsearch
**Created:** [December 31, 2012, 4:05pm UTC](https://discuss.elastic.co/t/problems-with-geo-shape-support/10207 "2012-12-31T16:05:56Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Jilles\_van\_Gurp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jilles_van_gurp/32/879_2.png) [@Jilles\_van\_Gurp](https://discuss.elastic.co/u/Jilles_van_Gurp)
#### Post date: [December 31, 2012, 4:05pm UTC](https://discuss.elastic.co/t/problems-with-geo-shape-support/10207/1 "2012-12-31T16:05:56Z")

</div>

> I've been trying to get geo spatial search to work with Elasticsearch.  
> The geo\_shape variety seems to do what I want and I'm interested in  
> indexing and retrieving points inside polygons. Simple radius search or  
> bounding box search is not good enough.

So, I indexed about 10 points in a simple test index and then ran the  
following query. Each point has a location field with type geo\_shape and a  
location field:  
{"id":"id0.1","type":"poi","name":{"en":["0.1"]},"location":{"type":"point",  
"coordinates":[52.1,13.1]}}

{"id":"id0.2","type":"poi","name":{"en":["0.2"]},"location":{"type":"point",  
"coordinates":[52.2,13.2]}}

{"id":"id0.3","type":"poi","name":{"en":["0.3"]},"location":{"type":"point",  
"coordinates":[52.3,13.3]}}

{"id":"id0.4","type":"poi","name":{"en":["0.4"]},"location":{"type":"point",  
"coordinates":[52.4,13.4]}}

{"id":"id0.5","type":"poi","name":{"en":["0.5"]},"location":{"type":"point",  
"coordinates":[52.5,13.5]}}

{"id":"id0.6","type":"poi","name":{"en":["0.6"]},"location":{"type":"point",  
"coordinates":[52.6,13.6]}}

{"id":"id0.7","type":"poi","name":{"en":["0.7"]},"location":{"type":"point",  
"coordinates":[52.7,13.7]}}

{"id":"id0.8","type":"poi","name":{"en":["0.8"]},"location":{"type":"point",  
"coordinates":[52.8,13.8]}}

{"id":"id0.9","type":"poi","name":{"en":["0.9"]},"location":{"type":"point",  
"coordinates":[52.9,13.9]}}

{"id":"id1.0","type":"poi","name":{"en":["1.0"]},"location":{"type":"point",  
"coordinates":[53.0,14.0]}}

I'm trying to run the following query:

{

> ```
> "query" : {
> "geo_shape" : {
> "location" : {
> "shape" : {
> "type" : "envelope",
> "coordinates" : [[52.0, 53.0],[13.0, 14.0]]
> },
> "relation" : "intersects"
> }
> }
> }
> 
> ```
> 
> }

I have several issues with this query and variants of it:

- what I really wanted is polygonal search, not an envelope search. Thius  
doesn't work at all. I get an npe if I use a polygon. For reference, here's  
the polygon I've been testing with, roughly corresponding to a circular  
area around Berlin

> [
> 
> [
> 
> 52.51795646971664,
> 
> 13.7939833902653
> 
> ],
> 
> [
> 
> 52.61972051694795,
> 
> 13.720499817631334
> 
> ],
> 
> [
> 
> 52.67575539585586,
> 
> 13.56279280917535
> 
> ],
> 
> [
> 
> 52.66465768725302,
> 
> 13.38110108186347
> 
> ],
> 
> [
> 
> 52.59066633862847,
> 
> 13.244824700054153
> 
> ],
> 
> [
> 
> 52.48204353028336,
> 
> 13.2060166097347
> 
> ],
> 
> [
> 
> 52.38027948305205,
> 
> 13.279500182368666
> 
> ],
> 
> [
> 
> 52.32424460414414,
> 
> 13.43720719082465
> 
> ],
> 
> [
> 
> 52.33534231274698,
> 
> 13.61889891813653
> 
> ],
> 
> [
> 
> 52.40933366137153,
> 
> 13.755175299945847
> 
> ]
> 
> ]
> 
> - what I really wanted is relation: contains. This doesn't work either. I  
> get a QueryParsingException[[myindex] Unknown shape operation [contains]]  
> if I try that

- if I run the above query, it fails with a TooManyClauses[maxClauseCount  
is set to 1024]

Obviously, I'm doing something very wrong. But what?

I.e. how do I actually search for points contained in a polygon of  
arbitrary size?

BTW. using Elasticsearch 0.20.2

--

---

<div class="post-metadata">

### Author: ![Jilles\_van\_Gurp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jilles_van_gurp/32/879_2.png) [@Jilles\_van\_Gurp](https://discuss.elastic.co/u/Jilles_van_Gurp)
#### Post date: [December 31, 2012, 4:13pm UTC](https://discuss.elastic.co/t/problems-with-geo-shape-support/10207/2 "2012-12-31T16:13:19Z")

</div>

It seems google groups messed up the formatting big time. Apologies. Here's  
the plain text version:

I've been trying to get geo spatial search to work with elastic search.  
The geo\_shape variety seems to do what I want and I'm interested in  
indexing and retrieving points inside polygons. Simple radius search or  
bounding box search is not good enough.

So, I indexed about a few points in a simple test index and then ran the  
following query. Each point has a location field with type geo\_shape and a  
location field:  
{"id":"id0.1","type":"poi","name":{"en":["0.1"]},"location":{"type":"point",  
"coordinates":[52.1,13.1]}}  
{"id":"id0.2","type":"poi","name":{"en":["0.2"]},"location":{"type":"point",  
"coordinates":[52.2,13.2]}}  
{"id":"id0.3","type":"poi","name":{"en":["0.3"]},"location":{"type":"point",  
"coordinates":[52.3,13.3]}}

etc.

I'm trying to run the following query:

{  
"query" : {  
"geo\_shape" : {  
"location" : {  
"shape" : {  
"type" : "envelope",  
"coordinates" : [[52.0, 53.0],[13.0, 14.0]]  
},  
"relation" : "intersects"  
}  
}  
}  
}

I have several issues with this query and variants of it:

- what I really wanted is polygonal search, not an envelope search. Thius  
doesn't work at all. I get an npe if I use a polygon. For reference, here's  
the polygon I've been testing with, roughly corresponding to a circular  
area around Berlin

[[ 52.51795646971664, 13.7939833902653], [ 52.61972051694795,  
13.720499817631334 ], [52.67575539585586, 13.56279280917535], [  
52.66465768725302, 13.38110108186347 ], [ 52.59066633862847,  
13.244824700054153 ], [52.48204353028336, 13.2060166097347], [  
52.38027948305205, 13.279500182368666 ], [ 52.32424460414414,  
13.43720719082465 ], [52.33534231274698, 13.61889891813653], [  
52.40933366137153, 13.755175299945847 ] ]

- what I really wanted is relation: contains. This doesn't work either. I  
get a QueryParsingException[[myindex] Unknown shape operation [contains]]  
if I try that

- if I run the above query, it fails with a TooManyClauses[maxClauseCount  
is set to 1024]

Obviously, I'm doing something very wrong. But what?

I.e. how do I actually search for points contained in a polygon of  
arbitrary size?

--

---

<div class="post-metadata">

### Author: ![Jilles\_van\_Gurp](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jilles_van_gurp/32/879_2.png) [@Jilles\_van\_Gurp](https://discuss.elastic.co/u/Jilles_van_Gurp)
#### Post date: [January 2, 2013, 2:38pm UTC](https://discuss.elastic.co/t/problems-with-geo-shape-support/10207/3 "2013-01-02T14:38:28Z")

</div>

I figured it out finally. If anyone else is struggling with this:

1. relation:contains should be relation:within, apparently this changed in  
the implementation. I created a pull request for the documentation fix
2. geojson polygons are 3d arrays and not 2d arrays. Passing in a 2d array  
causes the parser to throw an npe.
3. the polygon should end with the same coordinate as it begins with

So, this query is correct:

{

```
"query" : {

    "filtered" : {

    "query" : {

        "match_all" : {}

    },

    "filter" : {

     "geo_shape" : {

         "location" : {

             "shape" : {

                 "type" : "Polygon",

```

"coordinates" :  
[[[52.51795646971664,13.7939833902653],[52.61972051694795,13.720499817631334],[52.67575539585586,13.56279280917535],[52.66465768725302,13.38110108186347],[52.59066633862847,13.244824700054153],[52.48204353028336,13.2060166097347],[52.38027948305205,13.279500182368666],[52.32424460414414,13.43720719082465],[52.33534231274698,13.61889891813653],[52.40933366137153,13.755175299945847],[52.51795646971664,13.7939833902653]]]

},

```
             "relation" : "within"

         }

     }

 }

}

}

```

}

--

---

<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, 2:58am UTC](https://discuss.elastic.co/t/problems-with-geo-shape-support/10207/4 "2017-07-06T02:58:02Z")

</div>


