Manual indexing without listeners


is there a way to do manual indexing with the option autoregister_listeners set to false at Spring startup?

Here my conditionnal configuration

// start checkup
if (!profileService.hasProfileElasticSearch() || !isElasticSearchClusterUp()) {"disabling HibernateSearch listeners...");
	hibernateProperties.put("", "false");

And my manual indexing code

SearchSession searchSession = Search.session((EntityManager) sessionFactory.getCurrentSession());
SearchSessionWritePlan searchWritePlan = searchSession.writePlan();
searchWritePlan.addOrUpdate(rootRepository.get(getClassByName(type), id));

But when i call the searchWritePlan i get a beautiful HSEARCH800001: Hibernate Search was not initialized.

My use case for that example is :

  • i start my spring instance with a dead elasticsearch cluster
  • i fix my cluster but i can’t restart my spring instance yet
  • i would like a scheduling task to manual index entities while the situation is degraded

Thanks :slight_smile:

Hello, was renamed to just in recent versions, because, well… that’s what it does. Setting it to false will completely disable Hibernate Search.

If you just want to disable automatic indexing, you can set to none, as explained here.

Out of curiosity, why do you disable automatic indexing in that case? Is it just for performance reasons? If it is to avoid exceptions being thrown when entities are changed, you could simply use the async synchronization strategy (it was named queued before 6.0.0.Beta5), and then any failure to index will just result in logs: it won’t throw any exception. You will still be able to reindex manually when the Elasticsearch cluster is back up, and you may not have to restart your application.


it’s because if i don’t set autoregister_listeners to false with a shutdown cluster the startup is not working : HSEARCH400007: Elasticsearch request failed: Connection refused: no further information so i was trying to make it more resilient with conditional configuration

But … after another reading of my configuration the call made to elasticsearch is maybe triggered because of this :

hibernateProperties.put("", "yellow");


if(!isElasticSearchClusterUp()) {
	hibernateProperties.put("", "none");
} else {	 
 	hibernateProperties.put("", "yellow");

i tried to remove the status check when elasticsearch is dead, but still get the error at the startup

HSEARCH400080: Failed to detect the Elasticsearch version running on the cluster: HSEARCH400007: Elasticsearch request failed: Connection refused: no further information

In the meantime i check the documentation and i saw this :

Alternatively, you can tell Hibernate Search the Elasticsearch version to target. Hibernate Search will still query the Elasticsearch cluster to check that the configured version matches the actual version, but only after most of the metadata has been validated. This can be helpful when developing, in particular.

So i guess, it will not be possible to start with hibernate search enabled without elasticsearch up for now

Yes, that’s right. I suppose we could add a configuration option to disable version checking… However, that means you will have to provide the full Elasticsearch version (major and minor).
I created HSEARCH-3841 to address this eventually, because it’s actually something we’d need for applications started in docker-compose (the boot order of services in docker-compose is undefined).

Don’t hesitate to drop a comment if you have an idea about how to expose this feature, or if you want to contribute a patch.

i was able to do what i want with this :

what do you think about it @yrodiere ?

I merged it; thank you again for your contribution.

This will be part of the next release, in a few weeks.

In the meantime, you should be able to work with the snapshots that we publish to the JBoss Maven Repository.

Just change the version of Hibernate Search to 6.0.0-SNAPSHOT, and add this to your POM:

        Enable the JBoss Snapshots repository.
        <name>JBoss Public Maven Repository Group</name>
1 Like

Thanks to you !
Do not hesitate if you need some help :wink: