# Geo\_shapes and geo queries - can't figure out how to use them

**URL:** https://discuss.elastic.co/t/geo-shapes-and-geo-queries-cant-figure-out-how-to-use-them/11133
**Category:** Elasticsearch
**Created:** [March 13, 2013, 11:14am UTC](https://discuss.elastic.co/t/geo-shapes-and-geo-queries-cant-figure-out-how-to-use-them/11133 "2013-03-13T11:14:09Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Martin\_Bazik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/martin_bazik/32/2437_2.png) [@Martin\_Bazik](https://discuss.elastic.co/u/Martin_Bazik)
#### Post date: [March 13, 2013, 11:14am UTC](https://discuss.elastic.co/t/geo-shapes-and-geo-queries-cant-figure-out-how-to-use-them/11133/1 "2013-03-13T11:14:09Z")

</div>

i've been using elasticsearch a few months now to index regular data. Now i  
want to index some geospatial data, but can't figure it out.

i'm using elasticsearch 0.90 beta

the documents and query definition can be seen here

> <https://gist.github.com/bazo/5143339>

the second document and query are taken from documentation examples. i'm  
not sure whether location is a required name or some special property or i  
can name the field anyhow i want.

the mapping looks like this

test: {

properties: {

```
location: {

  type: geo_shape

}

```

}

}

when i run the query i get a Parse Failure [Failed to parse source  
[{"query":{"filtered":{"query":{"match\_all":[]},"filter":{"geo\_shape":{"location":{"shape":{"type":"envelope","coordinates":[[45,17],[49,18]]},"relation":"within"}}}}},"from":0,"size":15}]]];  
nested: IllegalArgumentException[no terms provided]; }]'

geo is the name of the index. the filter must be wrong, because when i run  
the query without the filter i get a list of all documents stored

what am i doing wrong and how i can fix it?

thanks

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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: [March 14, 2013, 1:58pm UTC](https://discuss.elastic.co/t/geo-shapes-and-geo-queries-cant-figure-out-how-to-use-them/11133/2 "2013-03-14T13:58:54Z")

</div>

Hey,

0.90 beta is not in the best of state regarding geo\_shape. I'm using a  
trunk snapshot. Anything from this week will include lucene 4.2 with some  
improvements regarding especially accuracy.

Another thing to be aware of is that the documentation is for stable and  
somewhat outdated since there have been a change: intersects is now the  
only supported relation for queries. Within no longer works.

In any case, the query looks fine except for the matchall.  
Try "query":{"match\_all":{}}

Jilles

On Wednesday, March 13, 2013 12:14:09 PM UTC+1, Martin Bažík wrote:

> i've been using elasticsearch a few months now to index regular data. Now  
> i want to index some geospatial data, but can't figure it out.
> 
> i'm using elasticsearch 0.90 beta
> 
> the documents and query definition can be seen here  
> [documents.json · GitHub](https://gist.github.com/bazo/5143339)
> 
> the second document and query are taken from documentation examples. i'm  
> not sure whether location is a required name or some special property or i  
> can name the field anyhow i want.
> 
> the mapping looks like this
> 
> test: {
> 
> properties: {
> 
> ```
> location: {
> 
> type: geo_shape
> 
> }
> 
> ```
> 
> }
> 
> }
> 
> when i run the query i get a Parse Failure [Failed to parse source  
> [{"query":{"filtered":{"query":{"match\_all":},"filter":{"geo\_shape":{"location":{"shape":{"type":"envelope","coordinates":[[45,17],[49,18]]},"relation":"within"}}}}},"from":0,"size":15}]]];  
> nested: IllegalArgumentException[no terms provided]; }]'
> 
> geo is the name of the index. the filter must be wrong, because when i run  
> the query without the filter i get a list of all documents stored
> 
> what am i doing wrong and how i can fix it?
> 
> thanks

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Martin\_Bazik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/martin_bazik/32/2437_2.png) [@Martin\_Bazik](https://discuss.elastic.co/u/Martin_Bazik)
#### Post date: [March 14, 2013, 4:13pm UTC](https://discuss.elastic.co/t/geo-shapes-and-geo-queries-cant-figure-out-how-to-use-them/11133/3 "2013-03-14T16:13:59Z")

</div>

thanks for the reply.

in which version are polygons supported?

have tried to save the following polygon in both 0.20.5 and 0.90beta(dont  
know how to compile the master source).

mapping:

{  
"polygon": {  
"properties": {  
"location": {  
"type": "geo\_shape"  
}  
}  
}  
}

the polygon document:

{  
"location": {  
"type": "polygon",  
"coordinates": [  
[  
48.2,  
17.1  
],  
[  
48.4,  
17.6  
],  
[  
48.9,  
18  
],  
[  
49.2,  
18.7  
],  
[  
48.7,  
21.3  
],  
[  
48.2,  
17.1  
]  
]  
}  
}

i get 'MapperParsingException[Failed to parse [location]]; nested:  
NullPointerException

so far i havent been able to save any shape.

my use is to save a bunch of polygons and then query intersecting polygons  
with a user given one.

but so far i can't make heads or tails of it

Dňa štvrtok, 14. marca 2013 14:58:54 UTC+1 Jilles van Gurp napísal(-a):

> Hey,
> 
> 0.90 beta is not in the best of state regarding geo\_shape. I'm using a  
> trunk snapshot. Anything from this week will include lucene 4.2 with some  
> improvements regarding especially accuracy.
> 
> Another thing to be aware of is that the documentation is for stable and  
> somewhat outdated since there have been a change: intersects is now the  
> only supported relation for queries. Within no longer works.
> 
> In any case, the query looks fine except for the matchall.  
> Try "query":{"match\_all":{}}
> 
> Jilles
> 
> On Wednesday, March 13, 2013 12:14:09 PM UTC+1, Martin Bažík wrote:
> 
> > i've been using elasticsearch a few months now to index regular data. Now  
> > i want to index some geospatial data, but can't figure it out.
> > 
> > i'm using elasticsearch 0.90 beta
> > 
> > the documents and query definition can be seen here  
> > [documents.json · GitHub](https://gist.github.com/bazo/5143339)
> > 
> > the second document and query are taken from documentation examples. i'm  
> > not sure whether location is a required name or some special property or i  
> > can name the field anyhow i want.
> > 
> > the mapping looks like this
> > 
> > test: {
> > 
> > properties: {
> > 
> > ```
> > location: {
> > 
> > type: geo_shape
> > 
> > }
> > 
> > ```
> > 
> > }
> > 
> > }
> > 
> > when i run the query i get a Parse Failure [Failed to parse source  
> > [{"query":{"filtered":{"query":{"match\_all":},"filter":{"geo\_shape":{"location":{"shape":{"type":"envelope","coordinates":[[45,17],[49,18]]},"relation":"within"}}}}},"from":0,"size":15}]]];  
> > nested: IllegalArgumentException[no terms provided]; }]'
> > 
> > geo is the name of the index. the filter must be wrong, because when i  
> > run the query without the filter i get a list of all documents stored
> > 
> > what am i doing wrong and how i can fix it?
> > 
> > thanks

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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: [March 14, 2013, 4:17pm UTC](https://discuss.elastic.co/t/geo-shapes-and-geo-queries-cant-figure-out-how-to-use-them/11133/4 "2013-03-14T16:17:59Z")

</div>

You are running in the same problem I was running into a couple of weeks  
ago: polygons are 3d arrays, not 2d arrays. The semantics is that the first  
element is the polygon and subsequent elements define holes in the polygon.

Additionally, the convention is to capitalize the type, so Polygon instead  
of polygon.

Both are geojson related things that you have to be aware of to figure it  
out.

Jilles

On Wednesday, March 13, 2013 12:14:09 PM UTC+1, Martin Bažík wrote:

> i've been using elasticsearch a few months now to index regular data. Now  
> i want to index some geospatial data, but can't figure it out.
> 
> i'm using elasticsearch 0.90 beta
> 
> the documents and query definition can be seen here  
> [documents.json · GitHub](https://gist.github.com/bazo/5143339)
> 
> the second document and query are taken from documentation examples. i'm  
> not sure whether location is a required name or some special property or i  
> can name the field anyhow i want.
> 
> the mapping looks like this
> 
> test: {
> 
> properties: {
> 
> ```
> location: {
> 
> type: geo_shape
> 
> }
> 
> ```
> 
> }
> 
> }
> 
> when i run the query i get a Parse Failure [Failed to parse source  
> [{"query":{"filtered":{"query":{"match\_all":},"filter":{"geo\_shape":{"location":{"shape":{"type":"envelope","coordinates":[[45,17],[49,18]]},"relation":"within"}}}}},"from":0,"size":15}]]];  
> nested: IllegalArgumentException[no terms provided]; }]'
> 
> geo is the name of the index. the filter must be wrong, because when i run  
> the query without the filter i get a list of all documents stored
> 
> what am i doing wrong and how i can fix it?
> 
> thanks

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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: [March 14, 2013, 4:20pm UTC](https://discuss.elastic.co/t/geo-shapes-and-geo-queries-cant-figure-out-how-to-use-them/11133/5 "2013-03-14T16:20:37Z")

</div>

Btw. compilation is pretty easy if you know how to use maven.

If not, install maven 3.x, make sure it is on your path (run maven -version  
to check)

Then checkout the github project for Elasticsearch and in the root type  
mvn clean install -DskipTests=true

Skipping the tests is usually a good idea because they take quite a bit of  
time to run.

That should compile things and create distribution packages in the target  
dir.

Jilles

On Wednesday, March 13, 2013 12:14:09 PM UTC+1, Martin Bažík wrote:

> i've been using elasticsearch a few months now to index regular data. Now  
> i want to index some geospatial data, but can't figure it out.
> 
> i'm using elasticsearch 0.90 beta
> 
> the documents and query definition can be seen here  
> [documents.json · GitHub](https://gist.github.com/bazo/5143339)
> 
> the second document and query are taken from documentation examples. i'm  
> not sure whether location is a required name or some special property or i  
> can name the field anyhow i want.
> 
> the mapping looks like this
> 
> test: {
> 
> properties: {
> 
> ```
> location: {
> 
> type: geo_shape
> 
> }
> 
> ```
> 
> }
> 
> }
> 
> when i run the query i get a Parse Failure [Failed to parse source  
> [{"query":{"filtered":{"query":{"match\_all":},"filter":{"geo\_shape":{"location":{"shape":{"type":"envelope","coordinates":[[45,17],[49,18]]},"relation":"within"}}}}},"from":0,"size":15}]]];  
> nested: IllegalArgumentException[no terms provided]; }]'
> 
> geo is the name of the index. the filter must be wrong, because when i run  
> the query without the filter i get a list of all documents stored
> 
> what am i doing wrong and how i can fix it?
> 
> thanks

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

### Author: ![Martin\_Bazik](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/martin_bazik/32/2437_2.png) [@Martin\_Bazik](https://discuss.elastic.co/u/Martin_Bazik)
#### Post date: [March 14, 2013, 5:28pm UTC](https://discuss.elastic.co/t/geo-shapes-and-geo-queries-cant-figure-out-how-to-use-them/11133/6 "2013-03-14T17:28:24Z")

</div>

i tried both polygon and Polygon, there was no difference.

now i see, that i miss one nested array. there's so mnay brackets 🙂

i will tri it right now.

i have never used maven before, can i compile es also on windows?

Dňa štvrtok, 14. marca 2013 17:20:37 UTC+1 Jilles van Gurp napísal(-a):

> Btw. compilation is pretty easy if you know how to use maven.
> 
> If not, install maven 3.x, make sure it is on your path (run maven  
> -version to check)
> 
> Then checkout the github project for Elasticsearch and in the root type  
> mvn clean install -DskipTests=true
> 
> Skipping the tests is usually a good idea because they take quite a bit of  
> time to run.
> 
> That should compile things and create distribution packages in the target  
> dir.
> 
> Jilles
> 
> On Wednesday, March 13, 2013 12:14:09 PM UTC+1, Martin Bažík wrote:
> 
> > i've been using elasticsearch a few months now to index regular data. Now  
> > i want to index some geospatial data, but can't figure it out.
> > 
> > i'm using elasticsearch 0.90 beta
> > 
> > the documents and query definition can be seen here  
> > [documents.json · GitHub](https://gist.github.com/bazo/5143339)
> > 
> > the second document and query are taken from documentation examples. i'm  
> > not sure whether location is a required name or some special property or i  
> > can name the field anyhow i want.
> > 
> > the mapping looks like this
> > 
> > test: {
> > 
> > properties: {
> > 
> > ```
> > location: {
> > 
> > type: geo_shape
> > 
> > }
> > 
> > ```
> > 
> > }
> > 
> > }
> > 
> > when i run the query i get a Parse Failure [Failed to parse source  
> > [{"query":{"filtered":{"query":{"match\_all":},"filter":{"geo\_shape":{"location":{"shape":{"type":"envelope","coordinates":[[45,17],[49,18]]},"relation":"within"}}}}},"from":0,"size":15}]]];  
> > nested: IllegalArgumentException[no terms provided]; }]'
> > 
> > geo is the name of the index. the filter must be wrong, because when i  
> > run the query without the filter i get a list of all documents stored
> > 
> > what am i doing wrong and how i can fix it?
> > 
> > thanks

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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: [March 15, 2013, 9:01am UTC](https://discuss.elastic.co/t/geo-shapes-and-geo-queries-cant-figure-out-how-to-use-them/11133/7 "2013-03-15T09:01:29Z")

</div>

It should work on windows, barring platform specific issues with packaging  
perhaps.

Jilles

On Thursday, March 14, 2013 6:28:24 PM UTC+1, Martin Bažík wrote:

> i tried both polygon and Polygon, there was no difference.
> 
> now i see, that i miss one nested array. there's so mnay brackets 🙂
> 
> i will tri it right now.
> 
> i have never used maven before, can i compile es also on windows?
> 
> Dňa štvrtok, 14. marca 2013 17:20:37 UTC+1 Jilles van Gurp napísal(-a):
> 
> > Btw. compilation is pretty easy if you know how to use maven.
> > 
> > If not, install maven 3.x, make sure it is on your path (run maven  
> > -version to check)
> > 
> > Then checkout the github project for Elasticsearch and in the root type  
> > mvn clean install -DskipTests=true
> > 
> > Skipping the tests is usually a good idea because they take quite a bit  
> > of time to run.
> > 
> > That should compile things and create distribution packages in the target  
> > dir.
> > 
> > Jilles
> > 
> > On Wednesday, March 13, 2013 12:14:09 PM UTC+1, Martin Bažík wrote:
> > 
> > > i've been using elasticsearch a few months now to index regular data.  
> > > Now i want to index some geospatial data, but can't figure it out.
> > > 
> > > i'm using elasticsearch 0.90 beta
> > > 
> > > the documents and query definition can be seen here  
> > > [documents.json · GitHub](https://gist.github.com/bazo/5143339)
> > > 
> > > the second document and query are taken from documentation examples. i'm  
> > > not sure whether location is a required name or some special property or i  
> > > can name the field anyhow i want.
> > > 
> > > the mapping looks like this
> > > 
> > > test: {
> > > 
> > > properties: {
> > > 
> > > ```
> > > location: {
> > > 
> > > type: geo_shape
> > > 
> > > }
> > > 
> > > ```
> > > 
> > > }
> > > 
> > > }
> > > 
> > > when i run the query i get a Parse Failure [Failed to parse source  
> > > [{"query":{"filtered":{"query":{"match\_all":},"filter":{"geo\_shape":{"location":{"shape":{"type":"envelope","coordinates":[[45,17],[49,18]]},"relation":"within"}}}}},"from":0,"size":15}]]];  
> > > nested: IllegalArgumentException[no terms provided]; }]'
> > > 
> > > geo is the name of the index. the filter must be wrong, because when i  
> > > run the query without the filter i get a list of all documents stored
> > > 
> > > what am i doing wrong and how i can fix it?
> > > 
> > > thanks

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:46am UTC](https://discuss.elastic.co/t/geo-shapes-and-geo-queries-cant-figure-out-how-to-use-them/11133/8 "2017-07-06T02:46:18Z")

</div>


