Skip to content

Instantly share code, notes, and snippets.

@springmeyer
Created April 12, 2011 01:32
Show Gist options
  • Save springmeyer/914754 to your computer and use it in GitHub Desktop.
Save springmeyer/914754 to your computer and use it in GitHub Desktop.
testing geo_bounding_box functionality in elastic search
# remove index
curl -XDELETE 'http://localhost:9200/geo/'
# {"ok":true,"acknowledged":true}
# add some data
curl -XPOST http://localhost:9200/geo/1 -d '{
"pin" : {
"location" : {
"lat" : 1.1,
"lon" : 1.2
}
}
}'
# {"ok":true,"_index":"geo","_type":"1","_id":"nJEwnlVTT92Lt9mXzAuFHA","_version":1}
# create mapping
curl -XPOST http://localhost:9200/geo/pin/_mapping -d '{
"properties" : {
"location" : { "type" : "geo_point" }
}
}'
# {"ok":true,"acknowledged":true}
# query data
curl -XGET http://localhost:9200/geo/_search -d '{
"query": { "match_all":{} }
}'
# responds with:
{"took":2,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max_score":1.0,"hits"[{"_index":"geo","_type":"1","_id":"nJEwnlVTT92Lt9mXzAuFHA","_score":1.0, "_source" : {
"pin" : {
"location" : {
"lat" : 1.1,
"lon" : 1.2
}
}
}}]}}
# query pin.location field
curl -XGET http://localhost:9200/geo/_search -d '{
"query" : {
"field" : { "pin.location.lat" : 1.1 }
}
}'
# same result as above
# this fails with: failed to find geo_point field [pin.location]]
curl -XGET http://localhost:9200/geo/_search -d '{
"query" : {
"match_all" : {}
},
"filter" : {
"geo_bounding_box" : {
"pin.location" : {
"top_left" : {
"lat" : 40.73,
"lon" : -74.1
},
"bottom_right" : {
"lat" : 40.717,
"lon" : -73.99
}
}
}
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment