Search when Elastic Search cluster is not available

Hi everyone,

is there a way to use hibernate search when elastic search cluster is not available?
I mean similar to projection where the query is made only on the elastic search cluster, is there a way to execute the query/transform the query from hibernate search only on own database?
I have already tried Search.toJpaQuery(query); and Search.toOrmQuery( query ); but these also need the elastic search cluster up and running.

Is there a way to implement a fallback without writing another query when elastic search cluster is not available?

Thank you in advance!

As I already answered, no there isn’t.

Automatically transforming the Hibernate Search query to an SQL query, is obviously not possible: if a database could do what Elasticsearch does, there would be no need to use Elasticsearch in the first place. An SQL query would necessarily be more limited, so there’s no way to do a 1-1 translation to SQL. You’ll need to decide how to translate some things that your DB doesn’t support, and that’s why it’s better to just re-implement the query yourself.

Anyway, if you can’t rely on Elasticsearch being available, maybe you just shouldn’t use Elasticsearch? There’s a Lucene backend as well, and that one only relies on the local filesystem, which hopefully will always be available. It won’t work if you have multiple instances of your application, though; see here.

If you just want to deploy the same application in different environments, some of which have Elasticsearch, some of which don’t, then you should be able to simply use a different backend (different configuration properties) in each environment: just add the dependencies for both the Elasticsearch backend and the Lucene backend to your application, and set the backend type through the configuration property (lucene or elasticsearch).

1 Like

thank you for the answer!