# Connectivity issues with Java client

**URL:** <https://discuss.elastic.co/t/connectivity-issues-with-java-client/43603>\
**Category:** Elasticsearch\
**Created:** [March 6, 2016, 7:19pm UTC](https://discuss.elastic.co/t/connectivity-issues-with-java-client/43603 "2016-03-06T19:19:58Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shawn\_Johnson](https://avatars.discourse-cdn.com/v4/letter/s/34f0e0/32.png) [@Shawn\_Johnson](https://discuss.elastic.co/u/Shawn_Johnson)\
**Post date:** [March 6, 2016, 7:19pm UTC](https://discuss.elastic.co/t/connectivity-issues-with-java-client/43603/1 "2016-03-06T19:19:58Z")

</div>

I have a simple two node cluster, and I'm trying to run a custom Java client (indexer-client-node0) on the same server as one of the 'data' (XX4) nodes. It happens that data-node2 (XX5) is master at the moment - which may to have some relevancy here?

I was able to connect the client previously when there was only one node, and the client and data nodes were on the same server. The problems began when the second data node was added.

Relevant log entries from client:

> 14:02:36,967 DEBUG [netty:895] [indexer-client-node0] connected to node [{#zen\_unicast\_1#}{10.10.XXX.XX4}{10.10.XXX.XX4:9300}]

> 14:02:38,259 DEBUG [zen:918] [indexer-client-node0] filtered ping responses: (filter\_client[true], filter\_data[false]) {none}

> 14:02:39,969 DEBUG [netty:1032] [indexer-client-node0] disconnecting from [{#zen\_unicast\_1#}{10.10.XXX.XX4}{10.10.XXX.XX4:9300}] due to explicit disconnect call

> 14:02:39,972 INFO [zen:443] [indexer-client-node0] failed to send join request to master [{elastic02}{e29o0UG4SmOWrtEcfs1u2Q}{10.10.XXX.XX5}{10.10.XXX.XX5:9300}], reason [RemoteTransportException[[elastic02][10.10.XXX.XX5:9300][internal:discovery/zen/join]]; nested: ConnectTransportException[[indexer-client-node0][127.0.0.1:9301] connect\_timeout[30s]]; nested: NotSerializableExceptionWrapper[Connection refused: /127.0.0.1:9301]; ]]

Version: Elasticsearch 2.1.1  
Both server elasticsearch.yml have:  
`network.host: _eth0_`

One settings I'm not sure about is - **discovery.zen.ping.unicast.hosts**. I have only one entry on each servers' elasticsearch.yml - and they are pointing to each other. Not quite sure if this is correct or not?

node1:  
**discovery.zen.ping.unicast.hosts** : elastic-data02

node2:  
**discovery.zen.ping.unicast.hosts** : elastic-data01

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [March 6, 2016, 8:19pm UTC](https://discuss.elastic.co/t/connectivity-issues-with-java-client/43603/2 "2016-03-06T20:19:07Z")

</div>

> [@Shawn\_Johnson](#):
>
> It happens that data-node2 (XX5) is master at the moment - which may to have some relevancy here?

Shouldn't.

> [@Shawn\_Johnson](#):
>
> I have only one entry on each servers' elasticsearch.yml - and they are pointing to each other. Not quite sure if this is correct or not?

It is correct.

> [@Shawn\_Johnson](#):
>
> Connection refused: /127.0.0.1:9301

This looks relevant. It seems the client is using port 9301, which is good, but why is it connecting to localhost?  
What's your connection string in the client look like?

---

<div class="post-metadata">

**Author:** ![Shawn\_Johnson](https://avatars.discourse-cdn.com/v4/letter/s/34f0e0/32.png) [@Shawn\_Johnson](https://discuss.elastic.co/u/Shawn_Johnson)\
**Post date:** [March 7, 2016, 12:45am UTC](https://discuss.elastic.co/t/connectivity-issues-with-java-client/43603/3 "2016-03-07T00:45:58Z")

</div>

Thanks @warkolm.

client elasticsearch.yml

> discovery.zen.ping.unicast.hosts: 10.10.XXX.XX4:9300

However, the above is actually not as IP, instead it's set as the domain name - in case that matters?

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [March 7, 2016, 12:47am UTC](https://discuss.elastic.co/t/connectivity-issues-with-java-client/43603/4 "2016-03-07T00:47:30Z")

</div>

That will depend on how the domain name is resolved, what does `ping hostdomainname` return?

---

<div class="post-metadata">

**Author:** ![Shawn\_Johnson](https://avatars.discourse-cdn.com/v4/letter/s/34f0e0/32.png) [@Shawn\_Johnson](https://discuss.elastic.co/u/Shawn_Johnson)\
**Post date:** [March 7, 2016, 1:25am UTC](https://discuss.elastic.co/t/connectivity-issues-with-java-client/43603/5 "2016-03-07T01:25:46Z")

</div>

Yes, it does resolve. Actually the data nodes also refer to one another by domain name. I also (just) switched the client-node to IP referral - appears to be the same results.

---

<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:** [March 7, 2016, 6:14am UTC](https://discuss.elastic.co/t/connectivity-issues-with-java-client/43603/6 "2016-03-07T06:14:55Z")

</div>

You should prefer the Transport client. Node client won't be supported in the future.

Note that the node client does not load anymore any elasticsearch.yml file from the classpath.

---

<div class="post-metadata">

**Author:** ![Shawn\_Johnson](https://avatars.discourse-cdn.com/v4/letter/s/34f0e0/32.png) [@Shawn\_Johnson](https://discuss.elastic.co/u/Shawn_Johnson)\
**Post date:** [March 7, 2016, 12:37pm UTC](https://discuss.elastic.co/t/connectivity-issues-with-java-client/43603/7 "2016-03-07T12:37:16Z")

</div>

@dadoonet - Thanks for the reply. Is that mentioned anywhere? I thought what I had read to this point was that the a Node-type client was preferred?

i.e.

> **[Java Clients for Elasticsearch](https://www.elastic.co/blog/found-java-clients-for-elasticsearch)**
>
> One of the important aspects of Elasticsearch is that it is programming language independent. All of the APIs for indexing, searching and monitoring can be accessed using HTTP and JSON so it can be integrated in any language that has those...

> The obvious first choice is to look at the client Elasticsearch provides natively.

---

<div class="post-metadata">

**Author:** ![mainec](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mainec/32/5557_2.png) [@mainec](https://discuss.elastic.co/u/mainec)\
**Post date:** [March 7, 2016, 1:15pm UTC](https://discuss.elastic.co/t/connectivity-issues-with-java-client/43603/8 "2016-03-07T13:15:18Z")

</div>

For a brief analysis on which native client to use see here:

[https://www.elastic.co/guide/en/elasticsearch/guide/current/\_transport\_client\_versus\_node\_client.html](https://www.elastic.co/guide/en/elasticsearch/guide/current/_transport_client_versus_node_client.html)

or here:

> **[Interfacing with Elasticsearch: Picking a Client
	  	 | Elastic](https://www.elastic.co/blog/found-interfacing-elasticsearch-picking-client)**
>
> When starting using Elasticsearch, it's easy to get confused about all the different ways to connect to Elasticsearch and why one of them should be preferred over the other. In this article we'll provide an overview of the different client types...

To quote from the advise in the page above: "If you’re using Java, the Transport client should be chosen over the Node client unless the performance gain from using a Node client turns out to be large enough to warrant the additional network complexity. Use benchmarks to verify the performance gains."

---

<div class="post-metadata">

**Author:** ![Shawn\_Johnson](https://avatars.discourse-cdn.com/v4/letter/s/34f0e0/32.png) [@Shawn\_Johnson](https://discuss.elastic.co/u/Shawn_Johnson)\
**Post date:** [March 17, 2016, 6:24pm UTC](https://discuss.elastic.co/t/connectivity-issues-with-java-client/43603/9 "2016-03-17T18:24:48Z")

</div>

Thanks all for your replies, switching to Transport client seems to be working much smoother.

---

<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, 11:07pm UTC](https://discuss.elastic.co/t/connectivity-issues-with-java-client/43603/10 "2017-07-05T23:07:30Z")

</div>


