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
--