0

I am building a Spring Boot application with elastic search and PostgreSQL.I am using PostgreSQL for writing purposes and elastic search for reading purposes. but I have stuck on some points.:

  1. Is we need to write separate model(POJO) classes for elastic search and PostgreSQL? because we are using ElasticsearchRepository for elastic search and JpaRepository.
  2. And also the annotations for elastic search are different and annotations for PostgreSQL are different on model classes.

Any body have idea what is the spring boot project structure where elastic search is used for reading purposes and PostgreSQL used for writing purposes.

  • Does this answer your question? [How do you use both Spring Data JPA and Spring Data Elasticsearch repositories on the same domain class in a Spring Boot application?](https://stackoverflow.com/questions/32878813/how-do-you-use-both-spring-data-jpa-and-spring-data-elasticsearch-repositories-o) – sidgate Jul 14 '22 at 08:49
  • according to the above link, they are using Document annotation on the model class but I am using PostgreSQL as a primary database and we cannot use Document annotation with postgresql – Kunal Bhangale Jul 14 '22 at 10:42

1 Answers1

-1

If you are using PostgreSQL as primary storage to store your data and Elasticsearch as secondary storage to index the data from PostgreSQL for searching. It is better to go with Logstash.

We are using Logstash as your other data stores will be relational databases, to keep them in sync with Elasticsearch

For implementing this you have to create a configuration file that connects PostgreSQL and elastic search. Use the JDBC input plugin and elastic search output plugin and run Logstash with that configuration file. Every document will be synced from there onward.

You can also go through this useful blog on how to keep elastic search synchronized with the relational database.

SARATHI
  • 126
  • 1
  • 7
  • Thank You for your response. The approach suggested by you is correct and I have already done that. But I am asking about spring boot level POJO classes. – Kunal Bhangale Jul 14 '22 at 07:23
  • My actual question: are we need to define separate model(POJO) classes for elastic search and PostgreSQL on spring boot. – Kunal Bhangale Jul 14 '22 at 07:23