Can I use geo polygon filter to retrieve hits based on polygon fields?


(Panagiotis) #1

In this example
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-geo-polygon-filter.html, I
see a query that will return hits of documents with points that are within
an area defined by a polygon. Is it possible to query for documents with
polygons that overlap with another polygon (e.g.
http://postgis.refractions.net/docs/images/st_overlaps03.png)?

Thank you,
Panagiotis

--
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.
For more options, visit https://groups.google.com/groups/opt_out.


(Alexander Reelsen) #2

Hey,

this does not work with geo_point types, but you can built it using the
geo_shape type. See

http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/mapping-geo-shape-type.html
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-geo-shape-query.html
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-geo-shape-filter.html

--Alex

On Mon, Nov 11, 2013 at 10:05 AM, Panagiotis liakospanagiotis@gmail.comwrote:

In this example
http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-geo-polygon-filter.html, I
see a query that will return hits of documents with points that are within
an area defined by a polygon. Is it possible to query for documents with
polygons that overlap with another polygon (e.g.
http://postgis.refractions.net/docs/images/st_overlaps03.png)?

Thank you,
Panagiotis

--
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.
For more options, visit https://groups.google.com/groups/opt_out.

--
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.
For more options, visit https://groups.google.com/groups/opt_out.


(Panagiotis) #3

Thank you Alexander,

I had managed to figure out on my own that I can use geo shapes to achieve
querying for intersecting objects. Now, I am wondering how costly it would
be to index geo spatial data with elasticsearch given the fact that I need
high precision. I wonder if anyone could point me to some stats so I do not
have to explore it on my own.

I include the steps that helped me find the answer to my original question
in case someone else faces the same problem.
The data don't make much sense, I used both points and shapes to explore
their differences.

--Panagiotis

  1. create index and mapping

curl -XPUT 'localhost:9200/locations_index'

curl -XPUT 'http://localhost:9200/locations_index/location/_mapping' -d '
{
"location":{
"properties":{
"longId":{
"type":"long",
"store":"yes"
},
"id":{
"include_in_all":"false",
"index":"not_analyzed",
"type":"string",
"store":"yes"
},
"pin":{
"type":"geo_point",
"store":"yes"
},
"shape": {
"type": "geo_shape",
"tree": "quadtree",
"precision": "1m"
}
}
}
}'

  1. populate index

curl -XPUT 'http://localhost:9200/locations_index/location/rd_1700' -d '
{
"longId": 1700,
"id": "id_1700",
"pin": {
"lat": 40.740000000000002,
"lon": 73.989999999999995
},
"shape" : {
"type" : "polygon",
"coordinates" : [
[ [50.0, 0.0], [51.0, 0.0], [51.0, 1.0], [50.0, 1.0], [50.0,
0.0] ]
]
}
}'

curl -XPUT 'http://localhost:9200/locations_index/location/rd_1701' -d '
{
"longId": 1701,
"id": "id_1701",
"pin": {
"lat": 30.740000000000002,
"lon": 65.989999999999995
},
"shape" : {
"type" : "polygon",
"coordinates" : [
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0], [100.0, 1.0],
[100.0, 0.0] ]
]
}
}
}'

  1. run a geo distance query (on geo_points)

curl -XGET 'http://localhost:9200/locations_index/location/_search' -d '
{
"from": 0,
"size": 10,
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"geo_distance": {
"distance": "10km",
"pin": {
"lat": 40.74,
"lon": 73.99
}
}
}
}
}
}'

  1. run a geo polygon query (on geo_points)

curl -XGET 'http://localhost:9200/locations_index/location/_search' -d '
{
"from": 0,
"size": 10,
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter" : {
"geo_polygon" : {
"pin" : {
"points" : [
{"lat" : 45, "lon" : 70},
{"lat" : 30, "lon" : 60},
{"lat" : 20, "lon" : 90}
]
}
}
}
}
}
}'

  1. run a geo shape query (on geo_shapes)

curl -XGET 'http://localhost:9200/locations_index/location/_search' -d '
{
"from": 0,
"size": 10,
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"geo_shape": {
"shape": {
"shape": {
"type" : "polygon",
"coordinates" : [
[ [100.0, 0.0], [101.0, 0.0], [101.0, 1.0],
[100.0, 1.0], [100.0, 0.0] ]
]
}
}
}
}
}
}
}'

--
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.
For more options, visit https://groups.google.com/groups/opt_out.


(system) #4