-
-
Save imotov/1043630 to your computer and use it in GitHub Desktop.
geo_distance test for ES
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
# 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