Skip to content

Instantly share code, notes, and snippets.

@imotov
Forked from mauricioalarcon/geo_distance_test
Created June 23, 2011 21:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imotov/1043630 to your computer and use it in GitHub Desktop.
Save imotov/1043630 to your computer and use it in GitHub Desktop.
geo_distance test for ES
# Delete all pins
curl -X DELETE "http://localhost:9200/pins/pin"
# Create proper mapping
curl -XPUT 'http://localhost:9200/pins/pin/_mapping' -d '
{
"pin" : {
"properties" : {
"location" : {
"type" : "geo_point"
}
}
}
}'
# Inserting a pin
curl -X POST "http://localhost:9200/pins/pin/1" -d '{
"pin" : {
"location" : {
"lat" : 40.12,
"lon" : -71.34
},
"tag" : ["food", "family"],
"text" : "my favorite family restaurant"
}
}'
# Checking it's there
curl -X GET "http://localhost:9200/pins/_search?pretty=true"
# Now let's search by geo_distance
curl -X GET "http://localhost:9200/pins/_search?pretty=true" -d '{
"query" : {
"filtered" : {
"query" : {
"match_all" : {}
},
"filter" : {
"geo_distance" : {
"distance" : "120km",
"pin.location" : {
"lat" : 40,
"lon" : -70
}
}
}
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment