I have a question about the multitenancy and hibernate search. I running a spring boot application (spring boot 2.2.4, hibernate search 6.0.0 and elasticsearch 7.4)
i have create a class that extends HandlerInterceptorAdapter for spring to determine the tenant from the httpRequest, i stock that in a thread local. i have implemented a class with MultiTenantConnectionProvider to switch the schema and override the 2 methodes : getConnection(String tenant). releaseConnection(String tenantIdentifier, Connection connection).
if my thread local have a tenant identifier that mean that i’m comme from a http request and i switch the tenant. With that i have create a entry point to reindex a tenant with hibernate search. If i call my entry point for each tenant elasticsearch index all data with tenant discriminator. -> Works !
If i launch my method with a @Scheduled(cron="") annotation i don’t come from a http request and hibernatesearch only index the default tenant. I create a loop to set like inside my httpinterceptor and set the tenant inside the thread local. the indexation is totaly random and the tenant resolver don’t work.
How can i set the tenant to hibernate search to index the correct tenant ?