This repository is the POC of my Geolocation and Elasticsearch post
I recommend this nice chrome extension "Sense" to interact with your server
PUT /countries
{
"mappings": {
"country": {
"properties": {
"name": {
"type": "string"
},
"location": {
"type": "geo_point"
}
}
}
}
}
The datasource comes from the excellent restcountries.eu API that we will rewrite to match Elasticsearch Bulk import format and geo_point format
This task can be achieve by running ./download.sh
. You will need the jq
command-line JSON processor
curl -s -XPOST localhost:9200/_bulk --data-binary "@countries";
GET /countries/_search
{
"size" : 100,
"query": {
"match_all": {}
}
}
GET /countries/_search
{
"size": 50,
"query": {
"bool": {
"must": {
"match_all": {}
},
"filter": {
"geo_distance": {
"distance": "3000km",
"location": {
"lat": 60,
"lon": -95
}
}
}
}
},
"sort": [
{
"_geo_distance": {
"location": {
"lat": 60,
"lon": -95
},
"order": "asc",
"unit": "km",
"distance_type": "sloppy_arc"
}
}
]
}