Home > Net >  Hibernate Search - Start application even if Elasticsearch cluster is down
Hibernate Search - Start application even if Elasticsearch cluster is down

Time:10-12

We integrated hibernate search into our crud microservices (simple spring boot apps) and it works like a charm. One fact that makes our architects nervous is that the crud services refuse to start when Elasticsearch is not running.

Is there any way to tell hibernate search that it should ignore the Elasticsearch cluster status?

CodePudding user response:

You can have Hibernate Search start without trying to reach Elasticsearch, and it's documented: https://docs.jboss.org/hibernate/stable/search/reference/en-US/html_single/#backend-elasticsearch-configuration-version

In short, set these properties:

hibernate.search.backend.version_check.enabled = false
hibernate.search.backend.version = 7.17
hibernate.search.schema_management.strategy = none

The downsides are:

  1. Hibernate Search won't be able to determine the version of Elasticsearch by itself (obviously, since Elasticsearch is potentially down), so you must provide that version yourself. If the version you provide is wrong, you run the risk of Hibernate Search using the wrong syntax or endpoints when calling Elasticsearch APIs.
  2. Hibernate Search won't create/validate the Elasticsearch schema on start (obviously, since Elasticsearch is potentially down), so you must make sure that the Elasticsearch schema is initialized (and valid) yourself (for example using manual schema management). Manual schema initialization may happen after startup, but must happen before you index/search (see below).
  3. Hibernate Search will still fail if asked to index something or run a query while Elasticsearch is down, but then there's nothing much you can do about that. Some people do manual checks on startup to see if Elasticsearch is down, and in that case disable Hibernate Search completely by setting configuration dynamically, so that at least they can still update entities in their database. But then their index no longer gets updated and search features are still unavailable.

EDIT: You can also address the third item (the fact that indexing will fail if Elasticsearch is down) by using the outbox-polling coordination strategy, which will record indexing events in the database and process them in the background instead of indexing directly. Indexing will still fail when Elasticsearch is in progress, but it will fail in some background process instead of the main application threads, and you will be able to have events reprocessed once Elasticsearch is back up.

  • Related