Created
June 28, 2011 02:11
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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