Nikolay Podolnyy
Nikolay Podolnyy

Reputation: 1091

Elasticsearch add data with Nodejs

I'm creating app with NodeJs and PostgreSQL and I whant to add ElasticSearch for it But I don't realize

Can someone help me? How add data to ElasticSearch and how sync my data between ElasticSearch and PostgreSQL? Thnq :)

Upvotes: 0

Views: 165

Answers (1)

MFARID
MFARID

Reputation: 720

  • Adding data to ElasticSearch is done by PUTing documents (https://www.elastic.co/guide/en/elasticsearch/reference/current/docs-index_.html)

  • Syncing data between postgres and ElasticSearch is a more complicated task. Assuming the data in the postgres tables change, you would need to mark what you indexed in ElasticSearch as indexed or processed, then continue processing. If tuples have a timestamp or incremental ids, then you can process tuples after indexing timestamp or last_processed_id.

You can run a cron job to keep syncing/updating your ElasticSearch indexes, or you can go fancy and write custom triggers in postgres that inserts/updates ElasticSearch documents.

I, personally, would go for triggers since data will be updated/inserted instantly in the ElasticSearch indexes.

Upvotes: 2

Related Questions