chirag
chirag

Reputation: 218

Connect to multiple elasticsearch hosts with different username and password

As per spring data elasticsearch reference documentation, we can have multiple comma separated hosts, but it takes a single username and password. Is it possible to configure different username and password per host?

For example, localhost:9200 -> username=user1 & password=password1, localhost:9300 ->username=username2 & password=password2

I'm using Spring Boot 2.5.2 with elasticsearch starter (which internally uses elasticsearch 4.2.x)

Upvotes: 0

Views: 539

Answers (1)

Abacus
Abacus

Reputation: 19471

Multiple hosts in the configuration are multiple nodes in the same cluster, and there you'd only have username/password.

You can principally create multiple ElasticsearchRestTemplate instances programmatically providing different ResHighLevelClientswhich you have to create by yourself as well, but this will not work with repositories, as there you will need a single bean of type ElasticsearchOperations. And it is not possible just by providing some configuration, but you'd need to setup up these by yourself.

Upvotes: 0

Related Questions