# Cannot start Node using Java API

**URL:** <https://discuss.elastic.co/t/cannot-start-node-using-java-api/6385>\
**Category:** Elasticsearch\
**Created:** [January 15, 2012, 2:56pm UTC](https://discuss.elastic.co/t/cannot-start-node-using-java-api/6385 "2012-01-15T14:56:59Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mp2893](https://avatars.discourse-cdn.com/v4/letter/m/d9b06d/32.png) [@mp2893](https://discuss.elastic.co/u/mp2893)\
**Post date:** [January 15, 2012, 2:56pm UTC](https://discuss.elastic.co/t/cannot-start-node-using-java-api/6385/1 "2012-01-15T14:56:59Z")

</div>

Hi,

## I'm a newbie in ES. I was trying to start a Java client using Java API. I used the following code:

```
    ImmutableSettings.Builder settings =

```

## ImmutableSettings.settingsBuilder(); settings.put("node.client", true); settings.put("node.data", false); settings.put("node.name", "temp"); settings.build(); Node node = NodeBuilder.nodeBuilder().settings(settings).node(); Client client = node.client();

## But I always get the following message:

## 12/01/15 22:46:46 INFO elasticsearch.node: [Hussar] {0.18.6}[1081]: initializing ... 12/01/15 22:46:46 INFO elasticsearch.plugins: [Hussar] loaded [], sites [] 12/01/15 22:46:47 INFO elasticsearch.node: [Hussar] {0.18.6}[1081]: initialized 12/01/15 22:46:47 INFO elasticsearch.node: [Hussar] {0.18.6}[1081]: starting ... 12/01/15 22:46:47 INFO elasticsearch.transport: [Hussar] bound\_address {inet[/0.0.0.0:9301]}, publish\_address {inet[/192.168.0.15:9301]} 12/01/15 22:47:17 WARN elasticsearch.discovery: [Hussar] waited for 30s and no initial state was set by the discovery 12/01/15 22:47:17 INFO elasticsearch.discovery: [Hussar] elasticsearch/ nJrZ15f7Tk-xu7VfKPjdFQ 12/01/15 22:47:17 INFO elasticsearch.http: [Hussar] bound\_address {inet[/0.0.0.0:9201]}, publish\_address {inet[/192.168.0.15:9201]} 12/01/15 22:47:17 INFO elasticsearch.node: [Hussar] {0.18.6}[1081]: started

## Then I when try to index a document, I get the following error message:

## Exception in thread "main" org.elasticsearch.discovery.MasterNotDiscoveredException: at org.elasticsearch.action.support.master.TransportMasterNodeOperationAction $3.onTimeout(TransportMasterNodeOperationAction.java:162) at org.elasticsearch.cluster.service.InternalClusterService $NotifyTimeout.run(InternalClusterService.java:332) 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:662)

## But if use TransportClient API and try to index a document(using the following code), everything goes smoothly.

```
    ImmutableSettings.Builder settings =

```

## ImmutableSettings.settingsBuilder(); settings.put("cluster.name", "anthread"); settings.put("client.transport.sniff", true); settings.build(); client = new TransportClient(settings); client.addTransportAddress(new InetSocketTransportAddress("192.168.0.15", 9300)); client.addTransportAddress(new InetSocketTransportAddress("192.168.0.7", 9300));

## And if I try to run an additional node using the following command: "./elasticsearch -f -Des.node.data=false -Des.node.client=true" I get the next message, which suggests that the master was found successfully, unlike the situation above.

## [2012-01-15 23:33:43,936][INFO][node] [anthread01] {0.18.6}[2130]: initializing ... [2012-01-15 23:33:43,944][INFO][plugins] [anthread01] loaded [], sites [] [2012-01-15 23:33:45,370][INFO][node] [anthread01] {0.18.6}[2130]: initialized [2012-01-15 23:33:45,371][INFO][node] [anthread01] {0.18.6}[2130]: starting ... [2012-01-15 23:33:45,418][INFO][transport] [anthread01] bound\_address {inet[/192.168.0.15:9301]}, publish\_address {inet[/192.168.0.15:9301]} [2012-01-15 23:33:48,527][INFO][cluster.service] [anthread01] detected\_master [anthread01][fegUJtU0QG60HaSDMe3wgg] [inet[/192.168.0.15:9300]], added {[anthread01][fegUJtU0QG60HaSDMe3wgg] [inet[/192.168.0.15:9300]],[anthread04][79-cnh1mTVu3HY\_3N6mv8w][inet[/ 192.168.0.4:9300]],[anthread03][uPw2gr6lRD2JHsxbvIurqw][inet[/ 192.168.0.8:9300]],[anthread02][gz-aUT28QbSL6ZGlMF9J3A][inet[/ 192.168.0.7:9300]],[anthread05][CH3NDGGCSzmrI-PVXtEXyg][inet[/ 192.168.0.5:9300]],}, reason: zen-disco-receive(from master [[anthread01][fegUJtU0QG60HaSDMe3wgg][inet[/192.168.0.15:9300]]]) [2012-01-15 23:33:48,540][INFO][discovery] [anthread01] anthread/\_\_eWuXJyT4iyitu186ISag [2012-01-15 23:33:48,543][INFO][http] [anthread01] bound\_address {inet[/192.168.0.15:9201]}, publish\_address {inet[/192.168.0.15:9201]} [2012-01-15 23:33:48,544][INFO][node] [anthread01] {0.18.6}[2130]: started [2012-01-15 23:33:52,709][INFO][node] [anthread01] {0.18.6}[2130]: stopping ... [2012-01-15 23:33:52,723][INFO][node] [anthread01] {0.18.6}[2130]: stopped [2012-01-15 23:33:52,723][INFO][node] [anthread01] {0.18.6}[2130]: closing ... [2012-01-15 23:33:52,732][INFO][node] [anthread01] {0.18.6}[2130]: closed

Could anyone tell me what I am doing wrong?  
I am assuming that when I start a node using Java API, the newly  
created node cannot find the existing cluster.  
But when I use TransportClient or "/bin/elasticsearch", everything  
goes fine. So I must be missing something here.  
My firewalls are all turned off, of course.  
I am really out of clue here.

Ed

---

<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:** [January 15, 2012, 10:34pm UTC](https://discuss.elastic.co/t/cannot-start-node-using-java-api/6385/2 "2012-01-15T22:34:52Z")

</div>

You don't seem to set the cluster name when you construct the node client?

On Sun, Jan 15, 2012 at 4:56 PM, mp2893 [mp2893@gmail.com](mailto:mp2893@gmail.com) wrote:

> Hi,
> 
> I'm a newbie in ES.  
> I was trying to start a Java client using Java API.  
> I used the following code:
> 
> * * *
> 
> ```
> ImmutableSettings.Builder settings =
> 
> ```
> 
> ImmutableSettings.settingsBuilder();  
> settings.put("node.client", true);  
> settings.put("node.data", false);  
> settings.put("node.name", "temp");  
> settings.build();  
> Node node =  
> NodeBuilder.nodeBuilder().settings(settings).node();  
> Client client = node.client();
> 
> * * *
> 
> But I always get the following message:
> 
> * * *
> 
> 12/01/15 22:46:46 INFO elasticsearch.node: [Hussar] {0.18.6}[1081]:  
> initializing ...  
> 12/01/15 22:46:46 INFO elasticsearch.plugins: [Hussar] loaded ,  
> sites   
> 12/01/15 22:46:47 INFO elasticsearch.node: [Hussar] {0.18.6}[1081]:  
> initialized  
> 12/01/15 22:46:47 INFO elasticsearch.node: [Hussar] {0.18.6}[1081]:  
> starting ...  
> 12/01/15 22:46:47 INFO elasticsearch.transport: [Hussar] bound\_address  
> {inet[/0.0.0.0:9301]}, publish\_address {inet[/192.168.0.15:9301]}  
> 12/01/15 22:47:17 WARN elasticsearch.discovery: [Hussar] waited for  
> 30s and no initial state was set by the discovery  
> 12/01/15 22:47:17 INFO elasticsearch.discovery: [Hussar] elasticsearch/  
> nJrZ15f7Tk-xu7VfKPjdFQ  
> 12/01/15 22:47:17 INFO elasticsearch.http: [Hussar] bound\_address  
> {inet[/0.0.0.0:9201]}, publish\_address {inet[/192.168.0.15:9201]}  
> 12/01/15 22:47:17 INFO elasticsearch.node: [Hussar] {0.18.6}[1081]:  
> started
> 
> * * *
> 
> Then I when try to index a document, I get the following error  
> message:
> 
> * * *
> 
> Exception in thread "main"  
> org.elasticsearch.discovery.MasterNotDiscoveredException:  
> at  
> org.elasticsearch.action.support.master.TransportMasterNodeOperationAction  
> $3.onTimeout(TransportMasterNodeOperationAction.java:162)  
> at org.elasticsearch.cluster.service.InternalClusterService  
> $NotifyTimeout.run(InternalClusterService.java:332)  
> 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:662)
> 
> * * *
> 
> But if use TransportClient API and try to index a document(using the  
> following code), everything goes smoothly.
> 
> * * *
> 
> ```
> ImmutableSettings.Builder settings =
> 
> ```
> 
> ImmutableSettings.settingsBuilder();  
> settings.put("cluster.name", "anthread");  
> settings.put("client.transport.sniff", true);  
> settings.build();  
> client = new TransportClient(settings);  
> client.addTransportAddress(new  
> InetSocketTransportAddress("192.168.0.15", 9300));  
> client.addTransportAddress(new  
> InetSocketTransportAddress("192.168.0.7", 9300));
> 
> * * *
> 
> And if I try to run an additional node using the following command:  
> "./elasticsearch -f -Des.node.data=false -Des.node.client=true"  
> I get the next message, which suggests that the master was found  
> successfully, unlike the situation above.
> 
> * * *
> 
> [2012-01-15 23:33:43,936][INFO][node]  
> [anthread01] {0.18.6}[2130]: initializing ...  
> [2012-01-15 23:33:43,944][INFO][plugins]  
> [anthread01] loaded , sites   
> [2012-01-15 23:33:45,370][INFO][node]  
> [anthread01] {0.18.6}[2130]: initialized  
> [2012-01-15 23:33:45,371][INFO][node]  
> [anthread01] {0.18.6}[2130]: starting ...  
> [2012-01-15 23:33:45,418][INFO][transport]  
> [anthread01] bound\_address {inet[/192.168.0.15:9301]}, publish\_address  
> {inet[/192.168.0.15:9301]}  
> [2012-01-15 23:33:48,527][INFO][cluster.service]  
> [anthread01] detected\_master [anthread01][fegUJtU0QG60HaSDMe3wgg]  
> [inet[/192.168.0.15:9300]], added {[anthread01][fegUJtU0QG60HaSDMe3wgg]  
> [inet[/192.168.0.15:9300]],[anthread04][79-cnh1mTVu3HY\_3N6mv8w][inet[/  
> 192.168.0.4:9300]],[anthread03][uPw2gr6lRD2JHsxbvIurqw][inet[/  
> 192.168.0.8:9300]],[anthread02][gz-aUT28QbSL6ZGlMF9J3A][inet[/  
> 192.168.0.7:9300]],[anthread05][CH3NDGGCSzmrI-PVXtEXyg][inet[/  
> 192.168.0.5:9300]],}, reason: zen-disco-receive(from master  
> [[anthread01][fegUJtU0QG60HaSDMe3wgg][inet[/192.168.0.15:9300]]])  
> [2012-01-15 23:33:48,540][INFO][discovery]  
> [anthread01] anthread/\_\_eWuXJyT4iyitu186ISag  
> [2012-01-15 23:33:48,543][INFO][http]  
> [anthread01] bound\_address {inet[/192.168.0.15:9201]}, publish\_address  
> {inet[/192.168.0.15:9201]}  
> [2012-01-15 23:33:48,544][INFO][node]  
> [anthread01] {0.18.6}[2130]: started  
> [2012-01-15 23:33:52,709][INFO][node]  
> [anthread01] {0.18.6}[2130]: stopping ...  
> [2012-01-15 23:33:52,723][INFO][node]  
> [anthread01] {0.18.6}[2130]: stopped  
> [2012-01-15 23:33:52,723][INFO][node]  
> [anthread01] {0.18.6}[2130]: closing ...  
> [2012-01-15 23:33:52,732][INFO][node]  
> [anthread01] {0.18.6}[2130]: closed
> 
> * * *
> 
> Could anyone tell me what I am doing wrong?  
> I am assuming that when I start a node using Java API, the newly  
> created node cannot find the existing cluster.  
> But when I use TransportClient or "/bin/elasticsearch", everything  
> goes fine. So I must be missing something here.  
> My firewalls are all turned off, of course.  
> I am really out of clue here.
> 
> Ed

---

<div class="post-metadata">

**Author:** ![mp2893](https://avatars.discourse-cdn.com/v4/letter/m/d9b06d/32.png) [@mp2893](https://discuss.elastic.co/u/mp2893)\
**Post date:** [January 16, 2012, 2:33am UTC](https://discuss.elastic.co/t/cannot-start-node-using-java-api/6385/3 "2012-01-16T02:33:34Z")

</div>

Yes, you were right.  
I added the following code:  
"settings.put("cluster.name", "myCluster");"  
and it worked like a charm.  
Thanks!!!

Ed

2012/1/16 Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com)

> You don't seem to set the cluster name when you construct the node client?
> 
> On Sun, Jan 15, 2012 at 4:56 PM, mp2893 [mp2893@gmail.com](mailto:mp2893@gmail.com) wrote:
> 
> > Hi,
> > 
> > I'm a newbie in ES.  
> > I was trying to start a Java client using Java API.  
> > I used the following code:
> > 
> > * * *
> > 
> > ```
> > ImmutableSettings.Builder settings =
> > 
> > ```
> > 
> > ImmutableSettings.settingsBuilder();  
> > settings.put("node.client", true);  
> > settings.put("node.data", false);  
> > settings.put("node.name", "temp");  
> > settings.build();  
> > Node node =  
> > NodeBuilder.nodeBuilder().settings(settings).node();  
> > Client client = node.client();
> > 
> > * * *
> > 
> > But I always get the following message:
> > 
> > * * *
> > 
> > 12/01/15 22:46:46 INFO elasticsearch.node: [Hussar] {0.18.6}[1081]:  
> > initializing ...  
> > 12/01/15 22:46:46 INFO elasticsearch.plugins: [Hussar] loaded ,  
> > sites   
> > 12/01/15 22:46:47 INFO elasticsearch.node: [Hussar] {0.18.6}[1081]:  
> > initialized  
> > 12/01/15 22:46:47 INFO elasticsearch.node: [Hussar] {0.18.6}[1081]:  
> > starting ...  
> > 12/01/15 22:46:47 INFO elasticsearch.transport: [Hussar] bound\_address  
> > {inet[/0.0.0.0:9301]}, publish\_address {inet[/192.168.0.15:9301]}  
> > 12/01/15 22:47:17 WARN elasticsearch.discovery: [Hussar] waited for  
> > 30s and no initial state was set by the discovery  
> > 12/01/15 22:47:17 INFO elasticsearch.discovery: [Hussar] elasticsearch/  
> > nJrZ15f7Tk-xu7VfKPjdFQ  
> > 12/01/15 22:47:17 INFO elasticsearch.http: [Hussar] bound\_address  
> > {inet[/0.0.0.0:9201]}, publish\_address {inet[/192.168.0.15:9201]}  
> > 12/01/15 22:47:17 INFO elasticsearch.node: [Hussar] {0.18.6}[1081]:  
> > started
> > 
> > * * *
> > 
> > Then I when try to index a document, I get the following error  
> > message:
> > 
> > * * *
> > 
> > Exception in thread "main"  
> > org.elasticsearch.discovery.MasterNotDiscoveredException:  
> > at  
> > org.elasticsearch.action.support.master.TransportMasterNodeOperationAction  
> > $3.onTimeout(TransportMasterNodeOperationAction.java:162)  
> > at org.elasticsearch.cluster.service.InternalClusterService  
> > $NotifyTimeout.run(InternalClusterService.java:332)  
> > 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:662)
> > 
> > * * *
> > 
> > But if use TransportClient API and try to index a document(using the  
> > following code), everything goes smoothly.
> > 
> > * * *
> > 
> > ```
> > ImmutableSettings.Builder settings =
> > 
> > ```
> > 
> > ImmutableSettings.settingsBuilder();  
> > settings.put("cluster.name", "anthread");  
> > settings.put("client.transport.sniff", true);  
> > settings.build();  
> > client = new TransportClient(settings);  
> > client.addTransportAddress(new  
> > InetSocketTransportAddress("192.168.0.15", 9300));  
> > client.addTransportAddress(new  
> > InetSocketTransportAddress("192.168.0.7", 9300));
> > 
> > * * *
> > 
> > And if I try to run an additional node using the following command:  
> > "./elasticsearch -f -Des.node.data=false -Des.node.client=true"  
> > I get the next message, which suggests that the master was found  
> > successfully, unlike the situation above.
> > 
> > * * *
> > 
> > [2012-01-15 23:33:43,936][INFO][node]  
> > [anthread01] {0.18.6}[2130]: initializing ...  
> > [2012-01-15 23:33:43,944][INFO][plugins]  
> > [anthread01] loaded , sites   
> > [2012-01-15 23:33:45,370][INFO][node]  
> > [anthread01] {0.18.6}[2130]: initialized  
> > [2012-01-15 23:33:45,371][INFO][node]  
> > [anthread01] {0.18.6}[2130]: starting ...  
> > [2012-01-15 23:33:45,418][INFO][transport]  
> > [anthread01] bound\_address {inet[/192.168.0.15:9301]}, publish\_address  
> > {inet[/192.168.0.15:9301]}  
> > [2012-01-15 23:33:48,527][INFO][cluster.service]  
> > [anthread01] detected\_master [anthread01][fegUJtU0QG60HaSDMe3wgg]  
> > [inet[/192.168.0.15:9300]], added {[anthread01][fegUJtU0QG60HaSDMe3wgg]  
> > [inet[/192.168.0.15:9300]],[anthread04][79-cnh1mTVu3HY\_3N6mv8w][inet[/  
> > 192.168.0.4:9300]],[anthread03][uPw2gr6lRD2JHsxbvIurqw][inet[/  
> > 192.168.0.8:9300]],[anthread02][gz-aUT28QbSL6ZGlMF9J3A][inet[/  
> > 192.168.0.7:9300]],[anthread05][CH3NDGGCSzmrI-PVXtEXyg][inet[/  
> > 192.168.0.5:9300]],}, reason: zen-disco-receive(from master  
> > [[anthread01][fegUJtU0QG60HaSDMe3wgg][inet[/192.168.0.15:9300]]])  
> > [2012-01-15 23:33:48,540][INFO][discovery]  
> > [anthread01] anthread/\_\_eWuXJyT4iyitu186ISag  
> > [2012-01-15 23:33:48,543][INFO][http]  
> > [anthread01] bound\_address {inet[/192.168.0.15:9201]}, publish\_address  
> > {inet[/192.168.0.15:9201]}  
> > [2012-01-15 23:33:48,544][INFO][node]  
> > [anthread01] {0.18.6}[2130]: started  
> > [2012-01-15 23:33:52,709][INFO][node]  
> > [anthread01] {0.18.6}[2130]: stopping ...  
> > [2012-01-15 23:33:52,723][INFO][node]  
> > [anthread01] {0.18.6}[2130]: stopped  
> > [2012-01-15 23:33:52,723][INFO][node]  
> > [anthread01] {0.18.6}[2130]: closing ...  
> > [2012-01-15 23:33:52,732][INFO][node]  
> > [anthread01] {0.18.6}[2130]: closed
> > 
> > * * *
> > 
> > Could anyone tell me what I am doing wrong?  
> > I am assuming that when I start a node using Java API, the newly  
> > created node cannot find the existing cluster.  
> > But when I use TransportClient or "/bin/elasticsearch", everything  
> > goes fine. So I must be missing something here.  
> > My firewalls are all turned off, of course.  
> > I am really out of clue here.
> > 
> > Ed

---

<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:42am UTC](https://discuss.elastic.co/t/cannot-start-node-using-java-api/6385/4 "2017-07-06T03:42:38Z")

</div>


