Using Spatial Data In Elasticsearch

Insert Into Index

Now that we have our index we can insert a document into it. To do this we're going to use a python loader which is in the loader directory of the repository.

Set up

Before running the loader - lets make sure we have the dependencies we need.

$ virtualenv LOADER
$ source LOADER/bin/activate
$ pip install numpy
$ brew create
$ brew install lzlib
$ brew install gdal
$ pip install pyes
$ pip install fiona
$ pip install shapely

Load a record

To load a record we'll use the loader - you can find out the parameters expected by the loader using:

$ python -h

To load a single suburb record you can use:

python '' 'suburbs'  'suburb' '../exercise_data/Melbourne-Localities/melbourne_locality_polygon.shp' 'id' --limit 1

The --limit optional argument specifies the number of records to load, in this case we only want to load one record.

Now we can test that our record has been loaded into Elasticsearch. Below we ask for the document indexed with the key 0 in the suburbs index.

$ curl  -s -XGET | python -m json.tool

This will present the json response from Elasticsearch