Code below is creating a bean to connect to elastic search cluster. The client used is Java High Level Rest Client. Here 2 connections have been made having port 9200 and 9201.
Let's say if I am running this in my local machine wherein I up the elastic search cluster and the default port is 9200, but what is the use case that we can achieve if we use multiple connections.
@Override
@Bean
public RestHighLevelClient elasticsearchClient() {
RestHighLevelClient client = new RestHighLevelClient(
RestClient.builder(
new HttpHost("localhost", 9200, "http"),
new HttpHost("localhost", 9201, "http")));
return client;
}
This is mentioned in the documentation: The high-level client will internally create the low-level client used to perform requests based on the provided builder. That low-level client maintains a pool of connections.
So are these threads in pool communicate with only one cluster or there are two clusters one with host 9200 and other with 9201