Created
September 9, 2013 11:49
-
-
Save amay077/6494561 to your computer and use it in GitHub Desktop.
Elasticsearch で位置情報を検索する手順 ref: http://qiita.com/amay077/items/9b63a554db340eb86212
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
curl -XPUT 'http://localhost:9200/myvenues/' | |
curl -XPUT 'http://localhost:9200/myvenues/venue/_mapping' -d ' | |
{ | |
"venue" : { | |
"properties" : { | |
"pin" : { "type" : "geo_point" } | |
} | |
} | |
}' |
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
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 | |
} | |
} | |
}' |
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
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 | |
} | |
} | |
} | |
} | |
} | |
}' |
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
{"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 | |
} | |
} | |
}}]}} |
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
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 | |
} | |
} | |
} | |
} | |
} | |
} | |
}' |
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
{"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 | |
} | |
} | |
}}]}} |
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
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] | |
] | |
} | |
} | |
} | |
} | |
} | |
}' |
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
{"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 | |
} | |
} | |
}}]}} |
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
{ | |
"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