# Connecting to a cluster

**URL:** <https://discuss.elastic.co/t/connecting-to-a-cluster/54169>\
**Category:** Elasticsearch\
**Created:** [June 28, 2016, 1:57pm UTC](https://discuss.elastic.co/t/connecting-to-a-cluster/54169 "2016-06-28T13:57:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dadepo](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadepo/32/19944_2.png) [@dadepo](https://discuss.elastic.co/u/dadepo)\
**Post date:** [June 28, 2016, 1:57pm UTC](https://discuss.elastic.co/t/connecting-to-a-cluster/54169/1 "2016-06-28T13:57:42Z")

</div>

I know ElasticSearch manages the creation of clusters automatically. Just have multiple nodes with the same cluster name and a cluster would be formed.

My question is from the application code side of things, when I am creating the `TransportClient` that I would use to connect to ElasticSearch, do I need to use a particular host? Or any host I used does not matter and ElasticSearch would ensure that I end up communicating with the cluster?

For example I have `hostA` and `hostB` with the same clusterName, when creating TransportClient do I need to use addTransportAddress to add both hosts? I would think this is the way to go. Or is there another way to create the TransportClient where I supply just the cluster name for instance?

---

<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:** [June 28, 2016, 2:12pm UTC](https://discuss.elastic.co/t/connecting-to-a-cluster/54169/2 "2016-06-28T14:12:34Z")

</div>

You could connect to whatever node of the cluster you wish.

If you have a 3 nodes cluster, I'd definitely provide the 3 IP addresses.

The transport client can not find "nodes" with only a cluster name.  
But: you can start locally a Node with master:false and data:false, then connect your TransportClient to 127.0.0.1 only.  
Then if you set the sniff option, it will be able to discover the rest of the cluster.

So: short answer:

> Or is there another way to create the TransportClient where I supply just the cluster name for instance?

No.

---

<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:** [July 5, 2017, 10:39pm UTC](https://discuss.elastic.co/t/connecting-to-a-cluster/54169/3 "2017-07-05T22:39:53Z")

</div>


