# Java api errors versus basic gets working fine

**URL:** https://discuss.elastic.co/t/java-api-errors-versus-basic-gets-working-fine/5517
**Category:** Elasticsearch
**Created:** [October 4, 2011, 11:52pm UTC](https://discuss.elastic.co/t/java-api-errors-versus-basic-gets-working-fine/5517 "2011-10-04T23:52:18Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Scott\_Decker](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@Scott\_Decker](https://discuss.elastic.co/u/Scott_Decker)
#### Post date: [October 4, 2011, 11:52pm UTC](https://discuss.elastic.co/t/java-api-errors-versus-basic-gets-working-fine/5517/1 "2011-10-04T23:52:18Z")

</div>

Hey All,  
I think this has got to be not setting up the Java API correctly.  
Have a box in ec2 that is running elasticsearch.  
locally, can get cluster status and health, and docs, etc.  
my my local dev, connecting to that box, using a basic get  
I can get cluster health/status, add docs, etc.

basically, I make a Java URL and do a get:  
(hacked example):  
URL urlPage = new URL(strUrl);

```
    HttpURLConnection urlConnection =

```

(HttpURLConnection)urlPage.openConnection();

However, when I try doing the same things with a TransportClient, I  
just hang there (if I use port 9200) or get No Node available (if I  
used port 9300)

Help on the transportclient setup would be much appreciated, because  
all other methods of connecting seem to work fine.

-code snippet-  
Settings settings = ImmutableSettings.settingsBuilder()  
.put("cluster.name", "cluster2")  
.put("client.transport.sniff", true).build();

```
    TransportClient client = new TransportClient(settings);

    client.addTransportAddress( new

```

InetSocketTransportAddress("", \<tried 9200 and  
9300 here\>));

right here is where it fails. it either hangs (port 9200)  
or, responds with "No Node Available" using port 9300

any ideas?

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [October 5, 2011, 9:57am UTC](https://discuss.elastic.co/t/java-api-errors-versus-basic-gets-working-fine/5517/2 "2011-10-05T09:57:01Z")

</div>

Using TransportClient, you should use port 9300, not 9200. If you talk  
remotely to an ec2 instance, you might not want to set sniff to true, this  
is because the publish address of the node might be the private IP, while  
you want to connect over the public IP (when sniff is set to true, the node  
publish IP is used to talk to it). Also, is port 9300 open?

On Wed, Oct 5, 2011 at 1:52 AM, Scott Decker [scott@publishthis.com](mailto:scott@publishthis.com) wrote:

> Hey All,  
> I think this has got to be not setting up the Java API correctly.  
> Have a box in ec2 that is running elasticsearch.  
> locally, can get cluster status and health, and docs, etc.  
> my my local dev, connecting to that box, using a basic get  
> I can get cluster health/status, add docs, etc.
> 
> basically, I make a Java URL and do a get:  
> (hacked example):  
> URL urlPage = new URL(strUrl);
> 
> ```
> HttpURLConnection urlConnection =
> 
> ```
> 
> (HttpURLConnection)urlPage.openConnection();
> 
> However, when I try doing the same things with a TransportClient, I  
> just hang there (if I use port 9200) or get No Node available (if I  
> used port 9300)
> 
> Help on the transportclient setup would be much appreciated, because  
> all other methods of connecting seem to work fine.
> 
> -code snippet-  
> Settings settings = ImmutableSettings.settingsBuilder()  
> .put("cluster.name", "cluster2")  
> .put("client.transport.sniff", true).build();
> 
> ```
> TransportClient client = new TransportClient(settings);
> 
> client.addTransportAddress( new
> 
> ```
> 
> InetSocketTransportAddress("", \<tried 9200 and  
> 9300 here\>));
> 
> right here is where it fails. it either hangs (port 9200)  
> or, responds with "No Node Available" using port 9300
> 
> any ideas?

---

<div class="post-metadata">

### Author: ![Scott\_Decker](https://avatars.discourse-cdn.com/v4/letter/s/7bcc69/32.png) [@Scott\_Decker](https://discuss.elastic.co/u/Scott_Decker)
#### Post date: [October 5, 2011, 5:10pm UTC](https://discuss.elastic.co/t/java-api-errors-versus-basic-gets-working-fine/5517/3 "2011-10-05T17:10:26Z")

</div>

Ahh, here is some info, in case anyone searches the groups looking for  
a similar answer.

Settings settings = ImmutableSettings.settingsBuilder()  
.put("cluster.name", "").build();

does the trick.

yes, port 9300 also needs to be used when setting up the  
transportclient.

here was the last one.

when building and getting the clusterhealthrequest  
i had this, which is what the javadoc said you could do:  
ClusterHealthRequest chr =  
Requests.clusterHealthRequest((String)null);

however, that causes a nullpointerexception in some .writeUTF

if you change it to:  
ClusterHealthRequest chr = Requests.clusterHealthRequest("");

then it works fine and the request will then work.

Thanks for the help on this Shay

On Oct 5, 2:57 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:

> Using TransportClient, you should use port 9300, not 9200. If you talk  
> remotely to an ec2 instance, you might not want to set sniff to true, this  
> is because the publish address of the node might be the private IP, while  
> you want to connect over the public IP (when sniff is set to true, the node  
> publish IP is used to talk to it). Also, is port 9300 open?
> 
> On Wed, Oct 5, 2011 at 1:52 AM, Scott Decker [sc...@publishthis.com](mailto:sc...@publishthis.com) wrote:
> 
> > Hey All,  
> > I think this has got to be not setting up the Java API correctly.  
> > Have a box in ec2 that is running elasticsearch.  
> > locally, can get cluster status and health, and docs, etc.  
> > my my local dev, connecting to that box, using a basic get  
> > I can get cluster health/status, add docs, etc.
> 
> > basically, I make a Java URL and do a get:  
> > (hacked example):  
> > URL urlPage = new URL(strUrl);
> 
> > ```
> > HttpURLConnection urlConnection =
> > 
> > ```
> > 
> > (HttpURLConnection)urlPage.openConnection();
> 
> > However, when I try doing the same things with a TransportClient, I  
> > just hang there (if I use port 9200) or get No Node available (if I  
> > used port 9300)
> 
> > Help on the transportclient setup would be much appreciated, because  
> > all other methods of connecting seem to work fine.
> 
> > -code snippet-  
> > Settings settings = ImmutableSettings.settingsBuilder()  
> > .put("cluster.name", "cluster2")  
> > .put("client.transport.sniff", true).build();
> 
> > ```
> > TransportClient client = new TransportClient(settings);
> > 
> > ```
> 
> > ```
> > client.addTransportAddress( new
> > 
> > ```
> > 
> > InetSocketTransportAddress("", \<tried 9200 and  
> > 9300 here\>));
> 
> > right here is where it fails. it either hangs (port 9200)  
> > or, responds with "No Node Available" using port 9300
> 
> > any ideas?

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [October 5, 2011, 6:04pm UTC](https://discuss.elastic.co/t/java-api-errors-versus-basic-gets-working-fine/5517/4 "2011-10-05T18:04:40Z")

</div>

Just don't pass anything in the health request parameter. For example:

client.admin().cluster().prepareHealth().setWaitForGreenStatus().execute().actionGet();

On Wed, Oct 5, 2011 at 7:10 PM, Scott Decker [scott@publishthis.com](mailto:scott@publishthis.com) wrote:

> Ahh, here is some info, in case anyone searches the groups looking for  
> a similar answer.
> 
> Settings settings = ImmutableSettings.settingsBuilder()  
> .put("cluster.name", "").build();
> 
> does the trick.
> 
> yes, port 9300 also needs to be used when setting up the  
> transportclient.
> 
> here was the last one.
> 
> when building and getting the clusterhealthrequest  
> i had this, which is what the javadoc said you could do:  
> ClusterHealthRequest chr =  
> Requests.clusterHealthRequest((String)null);
> 
> however, that causes a nullpointerexception in some .writeUTF
> 
> if you change it to:  
> ClusterHealthRequest chr = Requests.clusterHealthRequest("");
> 
> then it works fine and the request will then work.
> 
> Thanks for the help on this Shay
> 
> On Oct 5, 2:57 am, Shay Banon [kim...@gmail.com](mailto:kim...@gmail.com) wrote:
> 
> > Using TransportClient, you should use port 9300, not 9200. If you talk  
> > remotely to an ec2 instance, you might not want to set sniff to true,  
> > this  
> > is because the publish address of the node might be the private IP, while  
> > you want to connect over the public IP (when sniff is set to true, the  
> > node  
> > publish IP is used to talk to it). Also, is port 9300 open?
> > 
> > On Wed, Oct 5, 2011 at 1:52 AM, Scott Decker [sc...@publishthis.com](mailto:sc...@publishthis.com)  
> > wrote:
> > 
> > > Hey All,  
> > > I think this has got to be not setting up the Java API correctly.  
> > > Have a box in ec2 that is running elasticsearch.  
> > > locally, can get cluster status and health, and docs, etc.  
> > > my my local dev, connecting to that box, using a basic get  
> > > I can get cluster health/status, add docs, etc.
> > 
> > > basically, I make a Java URL and do a get:  
> > > (hacked example):  
> > > URL urlPage = new URL(strUrl);
> > 
> > > ```
> > > HttpURLConnection urlConnection =
> > > 
> > > ```
> > > 
> > > (HttpURLConnection)urlPage.openConnection();
> > 
> > > However, when I try doing the same things with a TransportClient, I  
> > > just hang there (if I use port 9200) or get No Node available (if I  
> > > used port 9300)
> > 
> > > Help on the transportclient setup would be much appreciated, because  
> > > all other methods of connecting seem to work fine.
> > 
> > > -code snippet-  
> > > Settings settings = ImmutableSettings.settingsBuilder()  
> > > .put("cluster.name", "cluster2")  
> > > .put("client.transport.sniff", true).build();
> > 
> > > ```
> > > TransportClient client = new TransportClient(settings);
> > > 
> > > ```
> > 
> > > ```
> > > client.addTransportAddress( new
> > > 
> > > ```
> > > 
> > > InetSocketTransportAddress("", \<tried 9200 and  
> > > 9300 here\>));
> > 
> > > right here is where it fails. it either hangs (port 9200)  
> > > or, responds with "No Node Available" using port 9300
> > 
> > > any ideas?

---

<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:52am UTC](https://discuss.elastic.co/t/java-api-errors-versus-basic-gets-working-fine/5517/5 "2017-07-06T03:52:45Z")

</div>


