user3615392
user3615392

Reputation: 91

Index data from PostgreSQL to Elasticsearch

I want to setup an elasticsearch cluster using multicast feature.One node is a external elasticsearch node and the other node is a node client (client property set as true-not hold data).

This node client is created using spring data elasticsearch. So I want to index data from postgresql database to external elasticsearch node.I had indexed data by using jdbc river plugin.

But I want to know is there any application that I can use for index data from postgresql instead of using the river plugin?

Upvotes: 0

Views: 3372

Answers (1)

Steve Smith
Steve Smith

Reputation: 388

It is possible to do this in realtime, although it requires writing a dedicated Postgres->ES gateway and using some Postgres-specific features. I've written about it here: http://haltcondition.net/2014/04/realtime-postgres-elasticsearch/

The principle is actually pretty simple, complexity of the method I have come up with is due to handling corner cases such as multiple gateways running and gateways becoming unavailable for a while. In short my solution is:

  • Attach a trigger to all tables of interest that copies the updated row IDs to a temporary table.
  • The trigger also emits an async notification that a row has been updated.
  • A separate gateway (mine is written in Clojure) attaches to the Postgres server and listens for notifications. This is the tricky part, as not all Postgres client drivers support async notifications (there is a new experimental JDBC driver that does, which is what I use).
  • On update the gateway reads, transforms and pushes the data to Elasticsearch.

In my experiments this model is capable of sub-second updates to Elasticsearch after a Postgres row insert/update. Obviously this will vary in the real world though.

There is a proof-of-concept project with Vagrant and Docker test frameworks here: https://bitbucket.org/tarkasteve/postgres-elasticsearch-realtime

Upvotes: 5

Related Questions