# How to configure Java RestClient to talk to ElasticCluster?

**URL:** <https://discuss.elastic.co/t/how-to-configure-java-restclient-to-talk-to-elasticcluster/143890>\
**Category:** Elasticsearch\
**Created:** [August 10, 2018, 3:21pm UTC](https://discuss.elastic.co/t/how-to-configure-java-restclient-to-talk-to-elasticcluster/143890 "2018-08-10T15:21:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![preraktiwari](https://avatars.discourse-cdn.com/v4/letter/p/e5b9ba/32.png) [@preraktiwari](https://discuss.elastic.co/u/preraktiwari)\
**Post date:** [August 10, 2018, 3:21pm UTC](https://discuss.elastic.co/t/how-to-configure-java-restclient-to-talk-to-elasticcluster/143890/1 "2018-08-10T15:21:59Z")

</div>

I am running ES v6.3.2. I have 2 master nodes and 2 data nodes in my cluster (lets call them M1 & M2 and D1 & D2). Lets say they are running on following IPs

```
    M1 : 10.20.30.1:9200
    M2 : 10.20.30.2:9200
    D1 : 10.20.30.3:9200
    D2 : 10.20.30.4:9200

```

I am communicating with the elastic search using the Low Level Java Rest Client.

On my local machine, I had only 1 instance running and I was communicating over (localhot:9200).

`HttpHost httpHost1 = new HttpHost("localhot", 9200, "http");`

My question is shall I build 4 HttpHost instances to talk to ES Cluster, or should I put all 4 ES instances behind the load balancer and build 1 HttpHost instance to talk to it?

---

<div class="post-metadata">

**Author:** ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)\
**Post date:** [August 20, 2018, 12:05pm UTC](https://discuss.elastic.co/t/how-to-configure-java-restclient-to-talk-to-elasticcluster/143890/2 "2018-08-20T12:05:46Z")

</div>

Hi,

the docs suggest to [initialize the client with all nodes](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-low-usage-initialization.html). Note that there is also a separate [Sniffer](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/_usage.html) that can auto-detect cluster nodes.

Daniel

---

<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:** [September 17, 2018, 12:05pm UTC](https://discuss.elastic.co/t/how-to-configure-java-restclient-to-talk-to-elasticcluster/143890/3 "2018-09-17T12:05:50Z")

</div>

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