Closed Rajkumar-Ramesh closed 1 month ago
Your problem is out of scope for Spring Data Elasticsearch. You have a Spring bean, the @Component DynamicAliasConfiguration
, this exists exactly once in your application context. And when manipulating this one instance from multiple threads - incoming requests - this will lead to errors as you already learned.
You should be able to solve this problem by properly scoping that bean (see https://docs.spring.io/spring-framework/reference/core/beans/factory-scopes.html), request or session scope should be the right one in your setup
Description:
We have a model called
Activity
, and the index name is dynamically set based onapplicationId
. In a Java multi-threaded environment, when concurrent requests come in, the index name can change during the execution of the first request, causing inconsistencies. Specifically, if two requests are processed simultaneously, the second request may alter the index name before completing the first request, leading to incorrect data being fetched or stored.Attempted Solution:
I tried modifying the repository method to accept IndexCoordinates, but it did not resolve the issue:
Is there a recommended approach for handling dynamic index names in a multi-threaded environment to avoid such conflicts? Any guidance or best practices would be greatly appreciated.