Query regarding multiple databases mapping to single elasticsearch

Hi,
We are trying to segregate our databases (postgres) on the basis of entities. Many of these entities are @Indexed into a single Elasticsearch at the moment. We have succeeded in getting the indexing part working for the entities even though they get saved/updated to different databases (outbox polling tables are created in each separate database).
We are facing some issue regarding the searching part though. Since, every query requires a SearchSession, and a SearchSession is created via EntityManager, is there any workaround to use multiple entitymanagers according to the _entity_type returned in search result?
We are using 6.1.7.Final version of the library.

Hi,

Not with the Hibernate ORM mapper, no. It is a core assumption that a SearchSession relies on one, and only one Hibernate ORM Session. And that’s unlikely to ever change.

In Hibernate Search 6.2, you could create a separate instance of Hibernate Search with the Standalone POJO mapper that would include all your entity classes, and then you would be able to use that for search across all entities. But if you want to load those entities from the database, you’ll have to implement that yourself; it is possible but definitely complex.

Thanks for the quick reply @yrodiere . We will look up the custom SelectionLoadingStrategy implementation if possible.

Please note this is only possible with the Stanadlone POJO mapper, which is completely separate from the Hibernate ORM mapper you’re currently using. It’s basically a different library.

I evaluated the change that we will have to do for Standalone POJO mapper, which is a lot :stuck_out_tongue: So, we will be using different SearchSessions for each EntityManager in parallel now to have the same logic of searching as before.
Thanks for the help @yrodiere