Skip to content

Instantly share code, notes, and snippets.

@dadoonet
Created December 26, 2012 13:12
Show Gist options
  • Save dadoonet/4380319 to your computer and use it in GitHub Desktop.
Save dadoonet/4380319 to your computer and use it in GitHub Desktop.
Geo Distance filter with Elasticsearch
curl -XDELETE localhost:9200/geopoint
curl -XPUT "localhost:9200/geopoint" -d '{
"settings" : { "index" : { "number_of_shards" : 1, "number_of_replicas" : 0 }}
}'
curl "localhost:9200/_cluster/health?wait_for_status=green&pretty=1&timeout=5s"
curl -XPUT 'http://localhost:9200/geopoint/tweet/_mapping' -d '
{
"tweet" : {
"properties" : {
"location" : {
"type" : "geo_point"
}
}
}
}'
curl -XPUT 'http://localhost:9200/geopoint/tweet/1' -d '
{
"name" : "Lemons lemons lemons",
"location" : { "lat": 32.72, "lon": -116.14}
}'
curl -XPUT 'http://localhost:9200/geopoint/tweet/2' -d '
{
"name" : "Apples too",
"location" : { "lat": 32.62, "lon": -116.25}
}'
curl -XPOST "localhost:9200/geopoint/_refresh"
curl -XGET 'http://localhost:9200/geopoint/tweet/_search?pretty=True' -d '
{
"query" : {
"match_all" : { }
},
"filter" : {
"geo_distance" : {
"distance" : "1km",
"location" : [ -116.25, 32.62]
}
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment