Asynchronously build Hibernate Search index to ensure no downtime.

Shubham Mishra :

We are using Hibernate Search (Lucene Engine) to enable fuzzy search for text some data we are storing in SQL Server database and consumed by a search service written in Java 8. The data source for the search is a table with moderate edit/update frequency. What we need is that for any change made while the index is rebuilt, we want to ensure that search function is still running and accessible instead of getting locked by process of index being built.

In short, how to temporarily use existing index while a new is being built and replace it on completion.

yrodiere :

Not an answer to your question, but that could help you anyway: from what I understood in your comments, you don't really need to fully rebuild the index, you just need to source update events from a different place than the application executing the search queries.

If your "updating" application uses Hibernate ORM, you can solve the issue without fully rebuilding the index: build the index automatically and incrementally in the "updating" application (using Hibernate Search in "automatic indexing" mode without ever doing any query), and make sure the index is made available to the "searching" applicaton.

The latter can be achieved either:

  • by using the experimental Elasticsearch integration and connecting both applications to the same cluster: one will update it, the other will use it to search.
  • or by using the Lucene integration with the filesystem-master/filesystem-slave directory providers, which will allow you to periodically (and without downtime) copy the index from the "updating" application (master) to the "searching" application (slave). Note that if multiple applications update the index, you will need to use the JMS or JGroups backend to redirect all index updates to a master node and avoid conflicts. Beware, configuring JMS or JGroups won't be obvious.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=103877&siteId=1