How can i connect to cluster when master node changed?

I have a cluster with three nodes on docker.
MasterNode:, Node2:, Node3:

I use Nest in .NetCore Application. and i connect to cluster with http://:9200/
and this connection works as well.
But when master node fails , connection to :9200 also fails!!!
What is the best approach for this situation?

I think you can define the 3 nodes in the client so any of the nodes will be used.

You can use a SniffingConnectionPool and seed it with the three nodes:

var uris = Enumerable.Range(9200, 3)
    .Select(port => new Uri($"{port}"));

var pool = new SniffingConnectionPool(uris);
var client = new ElasticClient(new ConnectionSettings(pool));

A sniffing connection pool will periodically sniff the cluster to find the nodes in the cluster. Sniffing uses the publish_address returned for each node, or the first bound_address if there's no publish_address, so ensure that the address returned for each node can be reached by the client. This can be controlled with HTTP or network settings.


As a personal preference I'd generally recommend starting with the StaticConnectionPool and moving to the SniffingConnectionPool later, and then only if you need the sniffing functionality. Many clusters don't need sniffing, or they have alternative mechanisms for finding the client nodes (e.g. DNS or a loadbalancer). Conversely we often see confusion around getting the publish_address right, particularly in today's world of Docker containers and their confusingly inhomogeneous networks. By starting with the StaticConnectionPool you can avoid that confusion until it's absolutely necessary.


Thanks :+1:

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.