Persisting entities to both database and search engine Persisting entities to both database and search engine elasticsearch elasticsearch

Persisting entities to both database and search engine


Check out the code from Hibernate Search. It syncs w Lucene and the db at the same time (or async if desired).

Or just use Hibernate Search.


Here is what I did in my former job:

In the service layer, after persisting entity with Hibernate, transform the entity using Jackson and send it to Elasticsearch.Of course, you can do that in the repo layer (DAO Layer) but I don't like it so much.

By the way, if you are using Spring, have a look at the Spring factory Project for Elasticsearch.