I’ve been using Elastic Search to build a searchable index of our PostgreSQL database. The PostGIS -enabled database contains timeseries and spatial objects. Spatial functionality in ES requires objects to have a mapping. When adding objects via a river , the trick is to first create the index, then create the mapping and only then create the river. This is a ‘for-future-reference’ article on how to get this all up and running. Assumptions:
Installing Elastic SearchHead over to the Elastic Search downloads page and download the tarball
Running ES is as easy as:
JDBC river plugin installationIn the ES directory, run the following installation command:
This will install the Elastic Search JDBC River by J?rg Prante . It requires a driver to work. Head over to the PostgreSQL JDBC drivers page to see which version of the JDBC driver you’ll need for your system. I’ve picked this one .
Download it to the
Restart or run ES:
Configuring Postgres RiverDelete the indices if you already created them:
It’s important create the index first:
Then, create the geo mapping:
Time to create the JDBC river. Specify the index in ‘index’ (should be ‘pumpstations’ in this case) and the mapping in ‘type’ (should be ‘pumpstation’, obviously).
This will cause the River to start bulk indexing your data. When it’s done, run the following query to see if it worked:
This should return documents with a If no documents are returned, try increasing the distance and/or check your lat/lon values. TroubleshootingIf data gets indexed but is not geo-searchable, check your mapping:
This should return a JSON object. Look for the
And not like a lat/lon pair. That’s it. Have fun with your PostGIS-to-ES river! |
|