elasticsearch/elasticsearch — pull request #2891 by spinscale (2013-04-13 08:08:40+00:00)
Title: Implementation to support geo circles (closes #2713)

This one is based on spatial4j in order to prevent the creation of an own geo_circle type.

The GeoJSON standard does not support circles. A proposal for this has been rejected:
https://github.com/GeoJSONWG/geojson-spec/wiki/Proposal---Circles-and-Ellipses-Geoms

This implementation extends the geo_shape parsers and serializers to support circles.

It works like this:

curl -X DELETE localhost:9200/geotest
curl -X PUT localhost:9200/geotest
curl -X PUT localhost:9200/geotest/geotest/_mapping -d '{ "geotest": { "properties": { "location" : { "type":"geo_shape" } } } }'

curl -X PUT localhost:9200/geotest/geotest/parkhotel?refresh=true -d '{ "name":"Park Hotel Amsterdam", "location" : { "type" : "point", "coordinates" : [4.883208, 52.362105] } }'
curl -X PUT localhost:9200/geotest/geotest/schiphol?refresh=true -d '{ "name":"Schiphol Airport", "location" : { "type" : "point", "coordinates" : [4.77253, 52.313096] } }'

echo "Querying with a radius of 10km (excluding the airport)"
curl -X POST localhost:9200/geotest/geotest/_search -d '{
"from":"0",
"size":"10",
"query" : {
"filtered" : {
"query": { "match_all" : {} },
"filter" : {
"geo_shape" : {
"location" : {
"shape" : {
"type" : "circle",
"coordinates" : [ 4.895439, 52.37125 ],
"radius": "10"
}
}
}
}
}
}
}'

echo "Querying with a radius of 15km (including the airport)"
curl -X POST localhost:9200/geotest/geotest/_search -d '{
"from":"0",
"size":"10",
"query" : {
"filtered" : {
"query": { "match_all" : {} },
"filter" : {
"geo_shape" : {
"location" : {
"shape" : {
"type" : "circle",
"coordinates" : [ 4.895439, 52.37125 ],
"radius": "15"
}
}
}
}
}
}
}'

TODO:
- Add real corner case tests