# How can i connect to cluster when master node changed?

**URL:** <https://discuss.elastic.co/t/how-can-i-connect-to-cluster-when-master-node-changed/258490>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [December 12, 2020, 6:50pm UTC](https://discuss.elastic.co/t/how-can-i-connect-to-cluster-when-master-node-changed/258490 "2020-12-12T18:50:02Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![hamidreza\_ghadir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hamidreza_ghadir/32/80756_2.png) [@hamidreza\_ghadir](https://discuss.elastic.co/u/hamidreza_ghadir)\
**Post date:** [December 12, 2020, 6:50pm UTC](https://discuss.elastic.co/t/how-can-i-connect-to-cluster-when-master-node-changed/258490/1 "2020-12-12T18:50:02Z")

</div>

Hi,  
I have a cluster with three nodes on docker.  
MasterNode: 0.0.0.0:9200, Node2: 0.0.0.0:9201, Node3: 0.0.0.0:9202

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?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [December 12, 2020, 8:13pm UTC](https://discuss.elastic.co/t/how-can-i-connect-to-cluster-when-master-node-changed/258490/2 "2020-12-12T20:13:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [December 13, 2020, 11:01pm UTC](https://discuss.elastic.co/t/how-can-i-connect-to-cluster-when-master-node-changed/258490/3 "2020-12-13T23:01:07Z")

</div>

You can use a [`SniffingConnectionPool`](https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/connection-pooling.html#sniffing-connection-pool) and seed it with the three nodes:

```auto
var uris = Enumerable.Range(9200, 3)
    .Select(port => new Uri($"http://0.0.0.0:{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](https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-http.html) or [network](https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-network.html) settings.

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [December 14, 2020, 7:00am UTC](https://discuss.elastic.co/t/how-can-i-connect-to-cluster-when-master-node-changed/258490/4 "2020-12-14T07:00:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![hamidreza\_ghadir](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/hamidreza_ghadir/32/80756_2.png) [@hamidreza\_ghadir](https://discuss.elastic.co/u/hamidreza_ghadir)\
**Post date:** [December 14, 2020, 7:15pm UTC](https://discuss.elastic.co/t/how-can-i-connect-to-cluster-when-master-node-changed/258490/5 "2020-12-14T19:15:13Z")

</div>

Thanks 👍  
@forloop  
@DavidTurner

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 11, 2021, 7:15pm UTC](https://discuss.elastic.co/t/how-can-i-connect-to-cluster-when-master-node-changed/258490/6 "2021-01-11T19:15:22Z")

</div>

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