'How to connect to multiple servers in spring data elasticsearch

I use the following configuration for elastic and I want to use multiple addresses instead of one

@Configuration
@EnableElasticsearchRepositories
class Config {

@Bean
fun client(): RestHighLevelClient {
    val clientConfiguration = ClientConfiguration.builder()
            .connectedTo("127.0.0.1:9200")
            .build()

    return RestClients.create(clientConfiguration).rest()
}

@Bean
fun elasticsearchTemplate(): ElasticsearchOperations {
    return ElasticsearchRestTemplate(client())
}

}



Solution 1:[1]

You can pass multiple host:port Strings to the connectedTo() method:

ClientConfiguration.builder()
            .connectedTo("IP_1:PORT_1", "IP_2:PORT_2")
            .build()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 P.J.Meisch