Reputation: 474
I am working with an Elasticsearch RestHighLevelClient
bean initialized by Spring when my app starts. Now I want to give users the ability to change the connection to Elasticsearch in run-time.
I wonder if there is any elegant way to update a connection to Elasticsearch nodes from a Java client (either the Low Level or the High Level). And by elegant I mean without having to reopen the client for every operation, nor with a flag to inform there was an update.
Upvotes: 0
Views: 126
Reputation: 17513
You can define several ES client beans in your Spring config and qualify (e.g. @Qualifier("one")
) them. Then at runtime you can lookup manually the best client by using ApplicationContext#getBean()
methods
Upvotes: 1
Reputation: 1971
I don't think that Elasticsearch would have such a possibility.
The solution you are looking for could be Connection Pool
. As you mentioned you want to avoid reopening connection for every operation, Connection Pool
allows you keeping a few open connections. This is a common pattern for managing many database connections.
Upvotes: 0