Skip to content

Instantly share code, notes, and snippets.

@john-bai
Created June 28, 2011 02:11
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save john-bai/1050346 to your computer and use it in GitHub Desktop.
Save john-bai/1050346 to your computer and use it in GitHub Desktop.
Working example on how to use geo_distance filter on Elastic Search
# Manually create the index
curl -XPUT 'http://localhost:9200/pins/'
# 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"
}
}'
# Since we're running these curl calls back to back, lets refresh
curl -XPOST 'http://localhost:9200/pins/_refresh'
# 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