# Need help connecting to elastic search cluster using java api

**URL:** <https://discuss.elastic.co/t/need-help-connecting-to-elastic-search-cluster-using-java-api/8063>\
**Category:** Elasticsearch\
**Created:** [June 12, 2012, 4:46pm UTC](https://discuss.elastic.co/t/need-help-connecting-to-elastic-search-cluster-using-java-api/8063 "2012-06-12T16:46:14Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![Upender\_Gilakathula](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/upender_gilakathula/32/2851_2.png) [@Upender\_Gilakathula](https://discuss.elastic.co/u/Upender_Gilakathula)\
**Post date:** [June 12, 2012, 4:46pm UTC](https://discuss.elastic.co/t/need-help-connecting-to-elastic-search-cluster-using-java-api/8063/1 "2012-06-12T16:46:14Z")

</div>

Hej all,  
I have created a Elastic Search cluster with 2 nodes in EC2 using the  
homepage documentation with out using any gateway. And Thats working fine.  
I can see that cluster helath and bigdesk all the stuff.

Here is my settings

cluster.name: broadwayrealtime  
cloud.aws.region: eu-west-1  
cloud:  
cloud.aws.region: eu-west-1  
aws:  
access\_key: XXXXXXX  
secret\_key: XXXXXXX  
discovery:  
type: ec2

node.master: true  
node.name: "Brendan Test"

But when I am trying to access through the JAVA api I am getting exception.

I am using the below settings to connect to this cluster using JAVA api.  
final ImmutableSettings.Builder settings =  
ImmutableSettings.settingsBuilder();  
settings.put("discovery.type", "ec2");  
settings.put("cloud.aws.access\_key", "access\_key");  
settings.put("cloud.aws.secret\_key", "secret\_key");  
settings.put("cloud.aws.region", "eu-west-1");  
settings.put("discovery.ec2.groups", "elasticsearch");  
Node node =  
NodeBuilder.nodeBuilder().settings(settings).clusterName("clusterName").client(true).node();  
client = node.client();

But I get this exception after 1 minute  
18:29:25.997 [New I/O client boss #1-0] WARN  
org.elasticsearch.transport.netty - [Mutant X] Exception caught on netty  
layer [[id: 0x129a41d2]]  
java.net.SocketException: Network is unreachable  
at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) ~[na:1.6.0\_31]  
at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:567)  
~[na:1.6.0\_31]  
at  
org.elasticsearch.common.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.connect(NioClientSocketPipelineSink.java:404)  
[elasticsearch-0.19.4.jar:na]  
at  
org.elasticsearch.common.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.processSelectedKeys(NioClientSocketPipelineSink.java:366)  
[elasticsearch-0.19.4.jar:na]  
at  
org.elasticsearch.common.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.run(NioClientSocketPipelineSink.java:282)  
[elasticsearch-0.19.4.jar:na]  
at  
org.elasticsearch.common.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:102)  
[elasticsearch-0.19.4.jar:na]  
at  
org.elasticsearch.common.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42)  
[elasticsearch-0.19.4.jar:na]  
at  
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)  
[na:1.6.0\_31]  
at  
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)  
[na:1.6.0\_31]  
at java.lang.Thread.run(Thread.java:680) [na:1.6.0\_31]

org.elasticsearch.discovery.MasterNotDiscoveredException: waited for [1m]  
at  
org.elasticsearch.action.support.master.TransportMasterNodeOperationAction$3.onTimeout(TransportMasterNodeOperationAction.java:169)  
at  
org.elasticsearch.cluster.service.InternalClusterService$NotifyTimeout.run(InternalClusterService.java:356)  
at  
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)  
at  
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)  
at java.lang.Thread.run(Thread.java:680)

Just to share the info; If I use like this its working fine.  
final ImmutableSettings.Builder settings =  
ImmutableSettings.settingsBuilder();  
settings.put("discovery.type", "ec2");  
settings.put("cloud.aws.access\_key", "access\_key");  
settings.put("cloud.aws.secret\_key", "secret\_key");  
settings.put("cloud.aws.region", "eu-west-1");  
settings.put("discovery.ec2.groups", "elasticsearch");  
final TransportClient transportClient = new TransportClient(settings)  
.addTransportAddress(new  
InetSocketTransportAddress("hostname", 9300))  
.addTransportAddress(new  
InetSocketTransportAddress("hostname", 9300))

Do I have to specify the hostnames like the above? which is kind of  
annoying to specify the host names? Shouldn't my java code find the cluster  
since I have specified everything such as clustername, discovery, access  
key, secret key. and region.

Many thanks for your help? I really appreciate your help.

---

<div class="post-metadata">

**Author:** ![Eric\_Jain](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eric_jain/32/834_2.png) [@Eric\_Jain](https://discuss.elastic.co/u/Eric_Jain)\
**Post date:** [June 12, 2012, 5:44pm UTC](https://discuss.elastic.co/t/need-help-connecting-to-elastic-search-cluster-using-java-api/8063/2 "2012-06-12T17:44:07Z")

</div>

On Jun 12, 9:46 am, Upender Gilakathula [upenderg...@gmail.com](mailto:upenderg...@gmail.com) wrote:

> But I get this exception after 1 minute  
> 18:29:25.997 [New I/O client boss #1-0] WARN  
> org.elasticsearch.transport.netty - [Mutant X] Exception caught on netty  
> layer [[id: 0x129a41d2]]  
> java.net.SocketException: Network is unreachable  
> at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) ~[na:1.6.0\_31]  
> at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:567)  
> ~[na:1.6.0\_31]

Are the machines all in the same security group, and are ports 9300 -  
9400 open?

---

<div class="post-metadata">

**Author:** ![Upender\_Gilakathula](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/upender_gilakathula/32/2851_2.png) [@Upender\_Gilakathula](https://discuss.elastic.co/u/Upender_Gilakathula)\
**Post date:** [June 12, 2012, 9:29pm UTC](https://discuss.elastic.co/t/need-help-connecting-to-elastic-search-cluster-using-java-api/8063/3 "2012-06-12T21:29:46Z")

</div>

Yes they are open.

22 (SSH)0.0.0.0/0Delete80 (HTTP)0.0.0.0/0Delete9200 - 93000.0.0.0/0Delete9300

- 94000.0.0.0/0Delete930010.0.0.0/8Delete  
On Tuesday, June 12, 2012 7:44:07 PM UTC+2, Eric Jain wrote:

> On Jun 12, 9:46 am, Upender Gilakathula [upenderg...@gmail.com](mailto:upenderg...@gmail.com) wrote:
> 
> > But I get this exception after 1 minute  
> > 18:29:25.997 [New I/O client boss #1-0] WARN  
> > org.elasticsearch.transport.netty - [Mutant X] Exception caught on  
> > netty  
> > layer [[id: 0x129a41d2]]  
> > java.net.SocketException: Network is unreachable  
> > at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)  
> > ~[na:1.6.0\_31]  
> > at  
> > sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:567)  
> > ~[na:1.6.0\_31]
> 
> Are the machines all in the same security group, and are ports 9300 -  
> 9400 open?

---

<div class="post-metadata">

**Author:** ![Upender\_Gilakathula](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/upender_gilakathula/32/2851_2.png) [@Upender\_Gilakathula](https://discuss.elastic.co/u/Upender_Gilakathula)\
**Post date:** [June 12, 2012, 9:30pm UTC](https://discuss.elastic.co/t/need-help-connecting-to-elastic-search-cluster-using-java-api/8063/4 "2012-06-12T21:30:54Z")

</div>

They are in the same security group ! Many thanks for a quick reply !

On Tuesday, June 12, 2012 11:29:46 PM UTC+2, Upender Gilakathula wrote:

> Yes they are open.
> 
> 22 (SSH)0.0.0.0/0Delete80 (HTTP)0.0.0.0/0Delete9200 - 93000.0.0.0/0Delete9300
> 
> - 94000.0.0.0/0Delete930010.0.0.0/8Delete  
> On Tuesday, June 12, 2012 7:44:07 PM UTC+2, Eric Jain wrote:
> 
> > On Jun 12, 9:46 am, Upender Gilakathula [upenderg...@gmail.com](mailto:upenderg...@gmail.com) wrote:
> > 
> > > But I get this exception after 1 minute  
> > > 18:29:25.997 [New I/O client boss #1-0] WARN  
> > > org.elasticsearch.transport.netty - [Mutant X] Exception caught on  
> > > netty  
> > > layer [[id: 0x129a41d2]]  
> > > java.net.SocketException: Network is unreachable  
> > > at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)  
> > > ~[na:1.6.0\_31]  
> > > at  
> > > sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:567)  
> > > ~[na:1.6.0\_31]
> > 
> > Are the machines all in the same security group, and are ports 9300 -  
> > 9400 open?

---

<div class="post-metadata">

**Author:** ![Eric\_Jain](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eric_jain/32/834_2.png) [@Eric\_Jain](https://discuss.elastic.co/u/Eric_Jain)\
**Post date:** [June 12, 2012, 10:00pm UTC](https://discuss.elastic.co/t/need-help-connecting-to-elastic-search-cluster-using-java-api/8063/5 "2012-06-12T22:00:55Z")

</div>

On Jun 12, 2:30 pm, Upender Gilakathula [upenderg...@gmail.com](mailto:upenderg...@gmail.com) wrote:

> They are in the same security group ! Many thanks for a quick reply !

Did you install the cloud-aws plugin?

[GitHub - elastic/elasticsearch-cloud-aws: AWS Cloud Plugin for Elasticsearch](https://github.com/elasticsearch/elasticsearch-cloud-aws)

---

<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 12, 2012, 10:05pm UTC](https://discuss.elastic.co/t/need-help-connecting-to-elastic-search-cluster-using-java-api/8063/6 "2012-06-12T22:05:48Z")

</div>

Are you making calls from a 10.xxx.xxx.xxx network ?  
What is this last rule ?

Le 12 juin 2012 à 23:30, Upender Gilakathula [upendergoud@gmail.com](mailto:upendergoud@gmail.com) a écrit :

> They are in the same security group ! Many thanks for a quick reply !
> 
> On Tuesday, June 12, 2012 11:29:46 PM UTC+2, Upender Gilakathula wrote:  
> Yes they are open.
> 
> 22 (SSH) 0.0.0.0/0 Delete  
> 80 (HTTP) 0.0.0.0/0 Delete  
> 9200 - 9300 0.0.0.0/0 Delete  
> 9300 - 9400 0.0.0.0/0 Delete  
> 9300 10.0.0.0/8 Delete
> 
> On Tuesday, June 12, 2012 7:44:07 PM UTC+2, Eric Jain wrote:  
> On Jun 12, 9:46 am, Upender Gilakathula [upenderg...@gmail.com](mailto:upenderg...@gmail.com) wrote:
> 
> > But I get this exception after 1 minute  
> > 18:29:25.997 [New I/O client boss #1-0] WARN  
> > org.elasticsearch.transport.netty - [Mutant X] Exception caught on netty  
> > layer [[id: 0x129a41d2]]  
> > java.net.SocketException: Network is unreachable  
> > at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) ~[na:1.6.0\_31]  
> > at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:567)  
> > ~[na:1.6.0\_31]
> 
> Are the machines all in the same security group, and are ports 9300 -  
> 9400 open?

---

<div class="post-metadata">

**Author:** ![Upender\_Gilakathula](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/upender_gilakathula/32/2851_2.png) [@Upender\_Gilakathula](https://discuss.elastic.co/u/Upender_Gilakathula)\
**Post date:** [June 13, 2012, 6:15am UTC](https://discuss.elastic.co/t/need-help-connecting-to-elastic-search-cluster-using-java-api/8063/7 "2012-06-13T06:15:04Z")

</div>

I have tried to run a program from my local machine with this ip  
starting 172.16.xxx.xxx  
And also from a amazon instances. Yes when I am testing from amazon the ip  
is 10.248.xx.xx

Either ways it didn't work.

On Wednesday, June 13, 2012 12:05:48 AM UTC+2, David Pilato wrote:

> Are you making calls from a 10.xxx.xxx.xxx network ?  
> What is this last rule ?
> 
> They are in the same security group ! Many thanks for a quick reply !
> 
> On Tuesday, June 12, 2012 11:29:46 PM UTC+2, Upender Gilakathula wrote:
> 
> > Yes they are open.
> > 
> > 22 (SSH)0.0.0.0/0Delete80 (HTTP)0.0.0.0/0Delete9200 - 93000.0.0.0/0Delete9300
> > 
> > - 94000.0.0.0/0Delete930010.0.0.0/8Delete  
> > On Tuesday, June 12, 2012 7:44:07 PM UTC+2, Eric Jain wrote:
> > 
> > > On Jun 12, 9:46 am, Upender Gilakathula [upenderg...@gmail.com](mailto:upenderg...@gmail.com) wrote:
> > > 
> > > > But I get this exception after 1 minute  
> > > > 18:29:25.997 [New I/O client boss #1-0] WARN  
> > > > org.elasticsearch.transport.netty - [Mutant X] Exception caught on  
> > > > netty  
> > > > layer [[id: 0x129a41d2]]  
> > > > java.net.SocketException: Network is unreachable  
> > > > at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)  
> > > > ~[na:1.6.0\_31]  
> > > > at  
> > > > sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:567)  
> > > > ~[na:1.6.0\_31]
> > > 
> > > Are the machines all in the same security group, and are ports 9300 -  
> > > 9400 open?

---

<div class="post-metadata">

**Author:** ![Upender\_Gilakathula](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/upender_gilakathula/32/2851_2.png) [@Upender\_Gilakathula](https://discuss.elastic.co/u/Upender_Gilakathula)\
**Post date:** [June 13, 2012, 6:18am UTC](https://discuss.elastic.co/t/need-help-connecting-to-elastic-search-cluster-using-java-api/8063/8 "2012-06-13T06:18:08Z")

</div>

Yes ! I did install the cloud-aws plugin. I have followed this  
page. [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/tutorials/2011/08/22/elasticsearch-on-ec2.html)

but i am not using any S3 Gateway configuration. since I am using EBS  
volumes.

On Wednesday, June 13, 2012 12:00:55 AM UTC+2, Eric Jain wrote:

> On Jun 12, 2:30 pm, Upender Gilakathula [upenderg...@gmail.com](mailto:upenderg...@gmail.com) wrote:
> 
> > They are in the same security group ! Many thanks for a quick reply !
> 
> Did you install the cloud-aws plugin?
> 
> [GitHub - elastic/elasticsearch-cloud-aws: AWS Cloud Plugin for Elasticsearch](https://github.com/elasticsearch/elasticsearch-cloud-aws)

---

<div class="post-metadata">

**Author:** ![Eric\_Jain](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eric_jain/32/834_2.png) [@Eric\_Jain](https://discuss.elastic.co/u/Eric_Jain)\
**Post date:** [June 13, 2012, 5:41pm UTC](https://discuss.elastic.co/t/need-help-connecting-to-elastic-search-cluster-using-java-api/8063/9 "2012-06-13T17:41:42Z")

</div>

On Jun 12, 9:46 am, Upender Gilakathula [upenderg...@gmail.com](mailto:upenderg...@gmail.com) wrote:

> cluster.name: broadwayrealtime  
> [...]  
> NodeBuilder.nodeBuilder().settings(settings).clusterName("clusterName").client(true).node();

In the code you're showing, you're not using the same cluster name?

---

<div class="post-metadata">

**Author:** ![Upender\_Gilakathula](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/upender_gilakathula/32/2851_2.png) [@Upender\_Gilakathula](https://discuss.elastic.co/u/Upender_Gilakathula)\
**Post date:** [June 14, 2012, 6:17am UTC](https://discuss.elastic.co/t/need-help-connecting-to-elastic-search-cluster-using-java-api/8063/10 "2012-06-14T06:17:08Z")

</div>

In my actual code I am using the clustername as "broadwayrealtime"; i just  
put as "clustername" when I am writing this post. sorry about that

On Wednesday, June 13, 2012 7:41:42 PM UTC+2, Eric Jain wrote:

> On Jun 12, 9:46 am, Upender Gilakathula [upenderg...@gmail.com](mailto:upenderg...@gmail.com) wrote:
> 
> > cluster.name: broadwayrealtime  
> > [...]
> 
> NodeBuilder.nodeBuilder().settings(settings).clusterName("clusterName").client(true).node();
> 
> In the code you're showing, you're not using the same cluster name?

---

<div class="post-metadata">

**Author:** ![Eric\_Jain](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/eric_jain/32/834_2.png) [@Eric\_Jain](https://discuss.elastic.co/u/Eric_Jain)\
**Post date:** [June 14, 2012, 6:02pm UTC](https://discuss.elastic.co/t/need-help-connecting-to-elastic-search-cluster-using-java-api/8063/11 "2012-06-14T18:02:50Z")

</div>

On Jun 13, 11:17 pm, Upender Gilakathula [upenderg...@gmail.com](mailto:upenderg...@gmail.com)  
wrote:

> In my actual code I am using the clustername as "broadwayrealtime"; i just  
> put as "clustername" when I am writing this post. sorry about that

You're using the latest version of elasticsearch and the cloud plugin,  
right?

Is the cloud-aws plugin (incl dependencies) in the classpath of the  
client application?

I don't set "discovery.ec2.groups", "node.master" or "node.name".  
Also, you set "cloud.aws.region" twice, but that shouldn't matter.

---

<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, 3:24am UTC](https://discuss.elastic.co/t/need-help-connecting-to-elastic-search-cluster-using-java-api/8063/12 "2017-07-06T03:24:12Z")

</div>


