# How to setup the ES cluster using the Client APIs

**URL:** https://discuss.elastic.co/t/how-to-setup-the-es-cluster-using-the-client-apis/20435
**Category:** Elasticsearch
**Created:** [October 26, 2014, 7:14pm UTC](https://discuss.elastic.co/t/how-to-setup-the-es-cluster-using-the-client-apis/20435 "2014-10-26T19:14:02Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Gaurav\_gupta](https://avatars.discourse-cdn.com/v4/letter/g/e274bd/32.png) [@Gaurav\_gupta](https://discuss.elastic.co/u/Gaurav_gupta)
#### Post date: [October 26, 2014, 7:14pm UTC](https://discuss.elastic.co/t/how-to-setup-the-es-cluster-using-the-client-apis/20435/1 "2014-10-26T19:14:02Z")

</div>

Hi,

Somehow the default multicast discovery is not working for me and I am  
exploring the unicast discovery mechanism to set up a ES cluster on two  
physical machines. I am am able to set up it using the default ES  
installation on two machines with configuring the both YML files to point  
to each other using UNICAST discovery. Now, I want to achieve the same  
thing using the ES Client API and I am using the below code for it. Could  
you let me know if below code is correct to point to two nodes in UNICAST  
or kindly point me to the right direction to refer the sample client code  
for it. I am facing issue in the below code and unicast discovery is also  
not working in below code.  
(I have around one week experience on ES and want to migrate one of the  
product from lucene to ES).

Settings settings1 = ImmutableSettings.settingsBuilder()  
.put("cluster.name", "PBcluster")  
.put("node.name","PBnode1")  
.put("node.master", true)  
.put("node.data", true)  
//.put("http.port", 9250)  
//.put("network.bind\_host", "152.144.214.62")  
// .put("network.publish\_host", "152.144.214.62")  
.put("discovery.zen.ping.multicast.enabled", false)  
// .put("discovery.zen.ping.unicast.hosts", "["152.144.226.12",  
"152.144.214.62"]")  
.put("discovery.zen.ping.unicast.hosts", "152.144.214.62")  
.put("discovery.zen.minimum\_master\_nodes", 1)  
.build();

node1 = nodeBuilder().settings(settings1).node();  
System.out.println("Starting node1...");  
node1.start();  
System.out.println("Started node1...");  
...  
Node clientNode =  
nodeBuilder().clusterName("PBcluster").client(true).node();  
Client client = clientNode.client();  
BulkRequestBuilder bulkRequest = client.prepareBulk();  
...

Thanks  
Gaurav

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CALZAj3L0B-h%2BbE%3D5p2MeMigf7jwSDC1FZhOC%3DnDfqtWsG-9Y0A%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CALZAj3L0B-h%2BbE%3D5p2MeMigf7jwSDC1FZhOC%3DnDfqtWsG-9Y0A%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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 6, 2017, 12:53am UTC](https://discuss.elastic.co/t/how-to-setup-the-es-cluster-using-the-client-apis/20435/2 "2017-07-06T00:53:50Z")

</div>


