Skip to content

POC of bulk importing and searching geolocation with Elasticsearch

License

Notifications You must be signed in to change notification settings

sylwit/geolocation-elasticsearch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Geolocation and Elasticsearch

This repository is the POC of my Geolocation and Elasticsearch post

I recommend this nice chrome extension "Sense" to interact with your server

Create Index

PUT /countries
{
  "mappings": {
    "country": {
      "properties": {
        "name": {
          "type": "string"
        },
        "location": {
          "type": "geo_point"
        }
      }
    }
  }
}

Download JSON file and create file to import

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

Bulk import

curl -s -XPOST localhost:9200/_bulk --data-binary "@countries";

List all countries

GET /countries/_search
{
   "size" : 100,
   "query": {
      "match_all": {}
   }
}

Filter by geo distance

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"
         }
      }
   ]
}

About

POC of bulk importing and searching geolocation with Elasticsearch

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages