Created
August 14, 2016 05:35
-
-
Save keitaj/7655b5c3e9daa888a438fc00709fb63a to your computer and use it in GitHub Desktop.
Elasticsearchを使って自分の周囲の位置情報を検索する ref: http://qiita.com/keitaj/items/5ab59387604801cb0532
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
{ | |
"mappings": { | |
"shop": { | |
"properties": { | |
"id": { | |
"type": "integer" | |
}, | |
"name": { | |
"type": "string" | |
}, | |
"address": { | |
"type": "string" | |
}, | |
"phone_number": { | |
"type": "string" | |
}, | |
"latidude": { | |
"type": "double" | |
}, | |
"longitude": { | |
"type": "double" | |
}, | |
"created": { | |
"format": "dateOptionalTime", | |
"type": "date" | |
}, | |
"updated": { | |
"format": "dateOptionalTime", | |
"type": "date" | |
}, | |
"geo_location": { | |
"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 -XPOST localhost:9200/shops?pretty -d @shops.json |
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 localhost:9200/shops/shop/1?pretty -d ' | |
{ | |
"id": "1", | |
"name": "Curry Shop", | |
"address": "東京都世田谷区経堂2丁目", | |
"phone_number": "000-0000-0000", | |
"latitude": 35.651045, | |
"longitude": 139.636139, | |
"created": "2015-09-01'T'05:26:07.062421", | |
"updated": "2015-10-02'T'03:02:51.777291", | |
"geo_location": [ 139.636139, 35.651045 ] | |
} | |
' |
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 localhost:9200/shops/shop/_search?pretty -d ' | |
{ | |
"query": { | |
"match_all" : {} | |
}, | |
"filter": { | |
"and": [ | |
{ | |
"geo_distance": { | |
"distance": "5km", | |
"geo_location": [ 139.62464, 35.647656 ] | |
} | |
} | |
] | |
}, | |
"sort": [ | |
{ | |
"_geo_distance": { | |
"geo_location": { | |
"lat": 35.647656, | |
"lon": 139.62464 | |
}, | |
"order": "asc", | |
"unit": "km", | |
"distance_type": "plane" | |
} | |
} | |
] | |
} | |
' |
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" : 10, | |
"timed_out" : false, | |
"_shards" : { | |
"total" : 5, | |
"successful" : 5, | |
"failed" : 0 | |
}, | |
"hits" : { | |
"total" : 1, | |
"max_score" : null, | |
"hits" : [ { | |
"_index" : "shops", | |
"_type" : "shop", | |
"_id" : "1", | |
"_score" : null, | |
"_source" : { | |
"id" : "1", | |
"name" : "Curry Shop", | |
"address" : "東京都世田谷区経堂4丁目", | |
"phone_number" : "000-0000-0000", | |
"latitude" : 35.651045, | |
"longitude" : 139.636139, | |
"created" : "2015-09-01T05:26:07.062421", | |
"updated" : "2015-10-02T03:02:51.777291", | |
"geo_location" : [ 139.636139, 35.651045 ] | |
}, | |
"sort" : [ 1.3344915446870738 ] | |
} ] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment