Skip to content

Instantly share code, notes, and snippets.

@imotov
Created April 24, 2012 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save imotov/2483149 to your computer and use it in GitHub Desktop.
Save imotov/2483149 to your computer and use it in GitHub Desktop.
# Delete all pins
curl -X DELETE "http://localhost:9200/pins"
echo
curl -XPUT 'http://localhost:9200/pins'
echo
# Create proper mapping
curl -XPUT 'http://localhost:9200/pins/pin/_mapping' -d '
{
"pin" : {
"properties" : {
"location" : {
"type" : "geo_point"
}
}
}
}'
echo
# 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"
}
}'
echo
curl -XPOST 'http://localhost:9200/pins/_refresh'
echo
curl -X GET "http://localhost:9200/pins/pin/_search?pretty=true" -d '{
"query" : {
"match_all" : {}
},
"fields": ["pin.location"],
"sort" : [
{
"_geo_distance" : {
"pin.location" : [-70, 40],
"order" : "asc",
"unit" : "km"
}
}
]
}'
{"ok":true,"acknowledged":true}
{"ok":true,"acknowledged":true}
{"ok":true,"acknowledged":true}
{"ok":true,"_index":"pins","_type":"pin","_id":"1","_version":1}
{"ok":true,"_shards":{"total":10,"successful":5,"failed":0}}
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 5,
"successful" : 5,
"failed" : 0
},
"hits" : {
"total" : 1,
"max_score" : null,
"hits" : [ {
"_index" : "pins",
"_type" : "pin",
"_id" : "1",
"_score" : null,
"fields" : {
"pin.location" : {
"lon" : -71.34,
"lat" : 40.12
}
},
"sort" : [ 114.81801790248922 ]
} ]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment