Skip to content

Instantly share code, notes, and snippets.

@amay077
Created September 9, 2013 11:49
Show Gist options
  • Save amay077/6494561 to your computer and use it in GitHub Desktop.
Save amay077/6494561 to your computer and use it in GitHub Desktop.
Elasticsearch で位置情報を検索する手順 ref: http://qiita.com/amay077/items/9b63a554db340eb86212
curl -XPUT 'http://localhost:9200/myvenues/'
curl -XPUT 'http://localhost:9200/myvenues/venue/_mapping' -d '
{
"venue" : {
"properties" : {
"pin" : { "type" : "geo_point" }
}
}
}'
curl -XPUT 'http://localhost:9200/myvenues/venue/1' -d '{
"name" : "Tokyo St",
"tag" : ["station", "train"],
"pin" : {
"location" : {
"lat" : 35.68,
"lon" : 139.76
}
}
}'
curl -XPUT 'http://localhost:9200/myvenues/venue/2' -d '{
"name" : "Nagoya St",
"tag" : ["station", "train"],
"pin" : {
"location" : {
"lat" : 35.17,
"lon" : 136.88
}
}
}'
curl -XPOST 'http://localhost:9200/myvenues/venue/_search' -d '{
"query": {
"filtered" : {
"query" : {
"match_all" : {}
},
"filter" : {
"geo_distance" : {
"distance" : "20km",
"venue.pin" : {
"lat" : 35.6,
"lon" : 139.8
}
}
}
}
}
}'
{"took":0,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max_score":1.0,"hits":[{"_index":"myvenues","_type":"venue","_id":"1","_score":1.0, "_source" : {
"name" : "Tokyo St",
"pin" : {
"location" : {
"lat" : 35.68,
"lon" : 139.76
}
}
}}]}}
curl -XPOST 'http://localhost:9200/myvenues/venue/_search' -d '{
"query": {
"filtered" : {
"query" : {
"match_all" : {}
},
"filter" : {
"geo_bounding_box" : {
"venue.pin" : {
"top_left" : {
"lat" : 35.2,
"lon" : 136.8
},
"bottom_right" : {
"lat" : 35.1,
"lon" : 136.9
}
}
}
}
}
}
}'
{"took":0,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max_score":1.0,"hits":[{"_index":"myvenues","_type":"venue","_id":"2","_score":1.0, "_source" : {
"name" : "Nagoya St",
"pin" : {
"location" : {
"lat" : 35.17,
"lon" : 136.88
}
}
}}]}}
curl -XPOST 'http://localhost:9200/myvenues/venue/_search' -d '{
"query": {
"filtered" : {
"query" : {
"match_all" : {}
},
"filter" : {
"geo_polygon" : {
"venue.pin" : {
"points" : [
[139.7, 35.7], // 経度が先!
[139.8, 35.7],
[139.8, 35.6],
[139.7, 35.6],
[139.7, 35.7]
]
}
}
}
}
}
}'
{"took":0,"timed_out":false,"_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":1,"max_score":1.0,"hits":[{"_index":"myvenues","_type":"venue","_id":"1","_score":1.0, "_source" : {
"name" : "Tokyo St",
"pin" : {
"location" : {
"lat" : 35.68,
"lon" : 139.76
}
}
}}]}}
{
"name" : "Tokyo St",
"pin" : {
"location" : {
"lat" : 35.68,
"lon" : 139.76
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment