Connecting to a cluster

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?

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.

1 Like