Skip to content

Instantly share code, notes, and snippets.

@lukecampbell
Created April 10, 2012 17:19
Show Gist options
  • Save lukecampbell/2352968 to your computer and use it in GitHub Desktop.
Save lukecampbell/2352968 to your computer and use it in GitHub Desktop.
Geo in ElasticSearch
curl -X DELETE "http://localhost:9200/venues"
curl -X POST "http://localhost:9200/venues"
curl -X POST "http://localhost:9200/venues/venue/_mapping" -d '
{
"venue" : {
"properties" : {
"name" : { "type" : "string" },
"pin" : {
"properties" : {
"location" : { "type" : "geo_point" }
}
}
}
}
}'
curl -X POST "http://localhost:9200/venues/venue" -d '
{
"name": "One",
"pin": {
"location": {
"lat": 50.071712,
"lon": 14.386832
}
}
}'
curl -X POST "http://localhost:9200/venues/venue" -d '
{
"name": "Two",
"pin": {
"location": {
"lat": 50.0566703786,
"lon": 14.4026255608
}
}
}'
curl -X POST "http://localhost:9200/venues/_refresh"
# Search Within 500m ARc
curl -X POST "http://localhost:9200/venues/_search?pretty=true" -d '
{
"query" : {
"filtered" : {
"query" : { "match_all" : {} },
"filter" : {
"geo_distance" : {
"distance" : "0.5km",
"pin.location" : {
"lat" : 50.071712,
"lon" : 14.386832
}
}
}
}
}
}'
# Search Within 5km Arc
curl -X POST "http://localhost:9200/venues/_search?pretty=true" -d '
{
"query" : {
"filtered" : {
"query" : { "match_all" : {} },
"filter" : {
"geo_distance" : {
"distance" : "5km",
"pin.location" : {
"lat" : 50.071712,
"lon" : 14.386832
}
}
}
}
}
}'
# Geo Distance Facet
curl -X POST "http://localhost:9200/venues/_search?pretty=true" -d '
{
"query" : {
"match_all" : {}
},
"facets" : {
"distance_count" : {
"geo_distance" : {
"pin.location" : {
"lat" : 50.071712,
"lon" : 14.386832
},
"ranges" : [
{ "to" : 1 },
{ "from" : 1, "to" : 5 },
{ "from" : 5, "to" : 10 }
]
}
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment