# Problem creating elasticsearch client under Apache Tomcat 7

**URL:** <https://discuss.elastic.co/t/problem-creating-elasticsearch-client-under-apache-tomcat-7/10370>\
**Category:** Elasticsearch\
**Created:** [January 16, 2013, 9:05am UTC](https://discuss.elastic.co/t/problem-creating-elasticsearch-client-under-apache-tomcat-7/10370 "2013-01-16T09:05:51Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Janusz\_Dalecki](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Janusz\_Dalecki](https://discuss.elastic.co/u/Janusz_Dalecki)\
**Post date:** [January 16, 2013, 9:05am UTC](https://discuss.elastic.co/t/problem-creating-elasticsearch-client-under-apache-tomcat-7/10370/1 "2013-01-16T09:05:51Z")

</div>

Hi,

I am running Apache Tomcat 7 from within Eclipse and running elasticsearch  
(port 9300/9200) on the same machine.

I am initializing the node within my ServletContextListener contextInitialized  
method using the following code:

```
  // Then we start our node for tests

  *node* = NodeBuilder.*nodeBuilder*().client(*true*).node();

  // We wait now for the yellow (or green) status

  *node*

```

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

… I am getting the following exception:

_org.elasticsearch.discovery.MasterNotDiscoveredException_: waited for  
[30s] at  
org.elasticsearch.action.support.master.TransportMasterNodeOperationAction$3.onTimeout(  
_TransportMasterNodeOperationAction.java:169_)

```
            at 

```

org.elasticsearch.cluster.service.InternalClusterService$NotifyTimeout.run(\*  
InternalClusterService.java:371\*)

```
            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*)

```

If I remove client(true) part:

```
  // Then we start our node for tests

  *node* = NodeBuilder.*nodeBuilder*().client(*true*).node();

  // We wait now for the yellow (or green) status

  *node*

```

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

… it starts without an exception but it also starts another server  
listening on 9301 (I have checked it using netstat).

Anybody has got clue what is going on here?

Regards,  
Janusz

--

---

<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:** [January 16, 2013, 12:31pm UTC](https://discuss.elastic.co/t/problem-creating-elasticsearch-client-under-apache-tomcat-7/10370/2 "2013-01-16T12:31:33Z")

</div>

Hi,

Starting a Client Node requires:

- A running Elasticsearch node
- With the same clustername

So, check that you have already a node running before starting your webapp.  
Check the clustername of this running node and check if you set the same cluster  
name for the embedded node. For example, add in your src/resources dir a copy of  
your elasticsearch.yml file or set the clusterName using the Java API.

Also, check if you have firewall rules that could block somehow your requests.

Does it help?

Le 16 janvier 2013 à 10:05, JD [jdalecki@tycoint.com](mailto:jdalecki@tycoint.com) a écrit :

> Hi,
> 
> I am running Apache Tomcat 7 from within Eclipse and running elasticsearch  
> (port 9300/9200) on the same machine.
> 
> I am initializing the node within my ServletContextListener  
> contextInitialized method using the following code:
> 
> ```
> // Then we start our node for tests
> 
> node = NodeBuilder.nodeBuilder().client(true).node();
> 
> // We wait now for the yellow (or green) status
> 
> node.client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();
> 
> ```
> 
> … I am getting the following exception:
> 
> org.elasticsearch.discovery.MasterNotDiscoveredException: waited for [30s] at  
> org.elasticsearch.action.support.master.TransportMasterNodeOperationAction$3.onTimeout(TransportMasterNodeOperationAction.java:169)
> 
> ```
> at
> 
> ```
> 
> org.elasticsearch.cluster.service.InternalClusterService$NotifyTimeout.run(InternalClusterService.java:371)
> 
> ```
> 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)
> 
> ```
> 
> If I remove client(true) part:
> 
> ```
> // Then we start our node for tests
> 
> node = NodeBuilder.nodeBuilder().client(true).node();
> 
> // We wait now for the yellow (or green) status
> 
> node.client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();
> 
> ```
> 
> … it starts without an exception but it also starts another server listening  
> on 9301 (I have checked it using netstat).
> 
> Anybody has got clue what is going on here?
> 
> Regards,  
> Janusz
> 
> --

--  
David Pilato  
[http://www.scrutmydocs.org/](http://www.scrutmydocs.org/)  
[http://dev.david.pilato.fr/](http://dev.david.pilato.fr/)  
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--

---

<div class="post-metadata">

**Author:** ![javanna](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/javanna/32/4698_2.png) [@javanna](https://discuss.elastic.co/u/javanna)\
**Post date:** [January 16, 2013, 3:54pm UTC](https://discuss.elastic.co/t/problem-creating-elasticsearch-client-under-apache-tomcat-7/10370/3 "2013-01-16T15:54:19Z")

</div>

David is right. That error means that you are most likely creating a brand  
new cluster with only the node that you create via java code.  
Saying client(true) is just a shortcut to say that the node won't contain  
data and cannot become a master. Of course if that's the only node in your  
cluster you have a problem because you must have a master in the cluster  
thus you get back that exception.

If you remove the client(true) your node can become master, thus no error,  
but you are still not joining the existing cluster that you meant to join.

As David wrote, you just need to check the name of the running cluster that  
you want to join (configured in config/elasticsearch.yml) and use it when  
you create the node like this:

_node_ = NodeBuilder._nodeBuilder_  
().clusterName("your\_cluster\_name").client(_true_).node();

Otherwise the default cluster name used is "elasticsearch".

Cheers,  
Luca

On Wednesday, January 16, 2013 10:05:51 AM UTC+1, JD wrote:

> Hi,
> 
> I am running Apache Tomcat 7 from within Eclipse and running elasticsearch  
> (port 9300/9200) on the same machine.
> 
> I am initializing the node within my ServletContextListener contextInitialized  
> method using the following code:
> 
> ```
> // Then we start our node for tests
> 
> *node* = NodeBuilder.*nodeBuilder*().client(*true*).node();
> 
> // We wait now for the yellow (or green) status
> 
> *node*
> 
> ```
> 
> .client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();
> 
> … I am getting the following exception:
> 
> _org.elasticsearch.discovery.MasterNotDiscoveredException_: waited for  
> [30s] at  
> org.elasticsearch.action.support.master.TransportMasterNodeOperationAction$3.onTimeout(  
> _TransportMasterNodeOperationAction.java:169_)
> 
> ```
> at 
> 
> ```
> 
> org.elasticsearch.cluster.service.InternalClusterService$NotifyTimeout.run(  
> _InternalClusterService.java:371_)
> 
> ```
> 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*)
> 
> ```
> 
> If I remove client(true) part:
> 
> ```
> // Then we start our node for tests
> 
> *node* = NodeBuilder.*nodeBuilder*().client(*true*).node();
> 
> // We wait now for the yellow (or green) status
> 
> *node*
> 
> ```
> 
> .client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();
> 
> … it starts without an exception but it also starts another server  
> listening on 9301 (I have checked it using netstat).
> 
> Anybody has got clue what is going on here?
> 
> Regards,  
> Janusz

--

---

<div class="post-metadata">

**Author:** ![Janusz\_Dalecki](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Janusz\_Dalecki](https://discuss.elastic.co/u/Janusz_Dalecki)\
**Post date:** [January 16, 2013, 10:58pm UTC](https://discuss.elastic.co/t/problem-creating-elasticsearch-client-under-apache-tomcat-7/10370/4 "2013-01-16T22:58:40Z")

</div>

Hi David,

1. 

```
 I have a running Elasticsearch local node – cluster name is 

```

“elasticsearch”

1. 

```
 Firewall is switched off

```

2. 

```
 I Have changed the code to:

```

// Then we start our node for tests

_node_ = NodeBuilder._nodeBuilder_().clusterName("elasticsearch"  
).data(_false_).client(_true_).node();

// We wait now for the yellow (or green) status

_node_  
.client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();

… I get the same problem.

Regards,

Janusz

On Wednesday, 16 January 2013 20:05:51 UTC+11, JD wrote:

> Hi,
> 
> I am running Apache Tomcat 7 from within Eclipse and running elasticsearch  
> (port 9300/9200) on the same machine.
> 
> I am initializing the node within my ServletContextListener contextInitialized  
> method using the following code:
> 
> ```
> // Then we start our node for tests
> 
> *node* = NodeBuilder.*nodeBuilder*().client(*true*).node();
> 
> // We wait now for the yellow (or green) status
> 
> *node*
> 
> ```
> 
> .client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();
> 
> … I am getting the following exception:
> 
> _org.elasticsearch.discovery.MasterNotDiscoveredException_: waited for  
> [30s] at  
> org.elasticsearch.action.support.master.TransportMasterNodeOperationAction$3.onTimeout(  
> _TransportMasterNodeOperationAction.java:169_)
> 
> ```
> at 
> 
> ```
> 
> org.elasticsearch.cluster.service.InternalClusterService$NotifyTimeout.run(  
> _InternalClusterService.java:371_)
> 
> ```
> 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*)
> 
> ```
> 
> If I remove client(true) part:
> 
> ```
> // Then we start our node for tests
> 
> *node* = NodeBuilder.*nodeBuilder*().client(*true*).node();
> 
> // We wait now for the yellow (or green) status
> 
> *node*
> 
> ```
> 
> .client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();
> 
> … it starts without an exception but it also starts another server  
> listening on 9301 (I have checked it using netstat).
> 
> Anybody has got clue what is going on here?
> 
> Regards,  
> Janusz

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [January 18, 2013, 5:07pm UTC](https://discuss.elastic.co/t/problem-creating-elasticsearch-client-under-apache-tomcat-7/10370/5 "2013-01-18T17:07:38Z")

</div>

Are you using the same version of elasticsearch for client and server?

On Wednesday, January 16, 2013 5:58:40 PM UTC-5, JD wrote:

> Hi David,
> 
> 1. 
> 
> ```
> I have a running Elasticsearch local node – cluster name is 
> 
> ```
> 
> “elasticsearch”
> 
> 1. 
> 
> ```
> Firewall is switched off
> 
> ```
> 
> 2. 
> 
> ```
> I Have changed the code to:
> 
> ```
> 
> // Then we start our node for tests
> 
> _node_ = NodeBuilder._nodeBuilder_().clusterName("elasticsearch"  
> ).data(_false_).client(_true_).node();
> 
> // We wait now for the yellow (or green) status
> 
> _node_  
> .client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();
> 
> … I get the same problem.
> 
> Regards,
> 
> Janusz
> 
> On Wednesday, 16 January 2013 20:05:51 UTC+11, JD wrote:
> 
> > Hi,
> > 
> > I am running Apache Tomcat 7 from within Eclipse and running  
> > elasticsearch (port 9300/9200) on the same machine.
> > 
> > I am initializing the node within my ServletContextListener contextInitialized  
> > method using the following code:
> > 
> > ```
> > // Then we start our node for tests
> > 
> > *node* = NodeBuilder.*nodeBuilder*().client(*true*).node();
> > 
> > // We wait now for the yellow (or green) status
> > 
> > *node*
> > 
> > ```
> > 
> > .client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();
> > 
> > … I am getting the following exception:
> > 
> > _org.elasticsearch.discovery.MasterNotDiscoveredException_: waited for  
> > [30s] at  
> > org.elasticsearch.action.support.master.TransportMasterNodeOperationAction$3.onTimeout(  
> > _TransportMasterNodeOperationAction.java:169_)
> > 
> > ```
> > at 
> > 
> > ```
> > 
> > org.elasticsearch.cluster.service.InternalClusterService$NotifyTimeout.run(  
> > _InternalClusterService.java:371_)
> > 
> > ```
> > 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*)
> > 
> > ```
> > 
> > If I remove client(true) part:
> > 
> > ```
> > // Then we start our node for tests
> > 
> > *node* = NodeBuilder.*nodeBuilder*().client(*true*).node();
> > 
> > // We wait now for the yellow (or green) status
> > 
> > *node*
> > 
> > ```
> > 
> > .client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();
> > 
> > … it starts without an exception but it also starts another server  
> > listening on 9301 (I have checked it using netstat).
> > 
> > Anybody has got clue what is going on here?
> > 
> > Regards,  
> > Janusz

--

---

<div class="post-metadata">

**Author:** ![Janusz\_Dalecki](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Janusz\_Dalecki](https://discuss.elastic.co/u/Janusz_Dalecki)\
**Post date:** [January 19, 2013, 4:30am UTC](https://discuss.elastic.co/t/problem-creating-elasticsearch-client-under-apache-tomcat-7/10370/6 "2013-01-19T04:30:12Z")

</div>

I am positive. Both elasticsearch and web server (WEB-INF\lib) are using  
elasticsearch-0.20.1.jar

Regards,  
Janusz

On Wednesday, January 16, 2013 8:05:51 PM UTC+11, JD wrote:

> Hi,
> 
> I am running Apache Tomcat 7 from within Eclipse and running elasticsearch  
> (port 9300/9200) on the same machine.
> 
> I am initializing the node within my ServletContextListener contextInitialized  
> method using the following code:
> 
> ```
> // Then we start our node for tests
> 
> *node* = NodeBuilder.*nodeBuilder*().client(*true*).node();
> 
> // We wait now for the yellow (or green) status
> 
> *node*
> 
> ```
> 
> .client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();
> 
> … I am getting the following exception:
> 
> _org.elasticsearch.discovery.MasterNotDiscoveredException_: waited for  
> [30s] at  
> org.elasticsearch.action.support.master.TransportMasterNodeOperationAction$3.onTimeout(  
> _TransportMasterNodeOperationAction.java:169_)
> 
> ```
> at 
> 
> ```
> 
> org.elasticsearch.cluster.service.InternalClusterService$NotifyTimeout.run(  
> _InternalClusterService.java:371_)
> 
> ```
> 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*)
> 
> ```
> 
> If I remove client(true) part:
> 
> ```
> // Then we start our node for tests
> 
> *node* = NodeBuilder.*nodeBuilder*().client(*true*).node();
> 
> // We wait now for the yellow (or green) status
> 
> *node*
> 
> ```
> 
> .client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();
> 
> … it starts without an exception but it also starts another server  
> listening on 9301 (I have checked it using netstat).
> 
> Anybody has got clue what is going on here?
> 
> Regards,  
> Janusz

--

---

<div class="post-metadata">

**Author:** ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)\
**Post date:** [January 19, 2013, 1:32pm UTC](https://discuss.elastic.co/t/problem-creating-elasticsearch-client-under-apache-tomcat-7/10370/7 "2013-01-19T13:32:34Z")

</div>

Did you change elasticsearch config in any way? Could you post  
elasticsearch server log here?

On Friday, January 18, 2013 11:30:12 PM UTC-5, JD wrote:

> I am positive. Both elasticsearch and web server (WEB-INF\lib) are using  
> elasticsearch-0.20.1.jar
> 
> Regards,  
> Janusz
> 
> On Wednesday, January 16, 2013 8:05:51 PM UTC+11, JD wrote:
> 
> > Hi,
> > 
> > I am running Apache Tomcat 7 from within Eclipse and running  
> > elasticsearch (port 9300/9200) on the same machine.
> > 
> > I am initializing the node within my ServletContextListener contextInitialized  
> > method using the following code:
> > 
> > ```
> > // Then we start our node for tests
> > 
> > *node* = NodeBuilder.*nodeBuilder*().client(*true*).node();
> > 
> > // We wait now for the yellow (or green) status
> > 
> > *node*
> > 
> > ```
> > 
> > .client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();
> > 
> > … I am getting the following exception:
> > 
> > _org.elasticsearch.discovery.MasterNotDiscoveredException_: waited for  
> > [30s] at  
> > org.elasticsearch.action.support.master.TransportMasterNodeOperationAction$3.onTimeout(  
> > _TransportMasterNodeOperationAction.java:169_)
> > 
> > ```
> > at 
> > 
> > ```
> > 
> > org.elasticsearch.cluster.service.InternalClusterService$NotifyTimeout.run(  
> > _InternalClusterService.java:371_)
> > 
> > ```
> > 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*)
> > 
> > ```
> > 
> > If I remove client(true) part:
> > 
> > ```
> > // Then we start our node for tests
> > 
> > *node* = NodeBuilder.*nodeBuilder*().client(*true*).node();
> > 
> > // We wait now for the yellow (or green) status
> > 
> > *node*
> > 
> > ```
> > 
> > .client().admin().cluster().prepareHealth().setWaitForYellowStatus().execute().actionGet();
> > 
> > … it starts without an exception but it also starts another server  
> > listening on 9301 (I have checked it using netstat).
> > 
> > Anybody has got clue what is going on here?
> > 
> > Regards,  
> > Janusz

--

---

<div class="post-metadata">

**Author:** ![Arun\_Sankar](https://avatars.discourse-cdn.com/v4/letter/a/f14d63/32.png) [@Arun\_Sankar](https://discuss.elastic.co/u/Arun_Sankar)\
**Post date:** [May 24, 2013, 10:38am UTC](https://discuss.elastic.co/t/problem-creating-elasticsearch-client-under-apache-tomcat-7/10370/8 "2013-05-24T10:38:22Z")

</div>

Hi,  
I am also facing the same issue.

Did you manage to resolve this?

Please let me know.

Arun

---

<div class="post-metadata">

**Author:** ![Arun\_Sankar](https://avatars.discourse-cdn.com/v4/letter/a/f14d63/32.png) [@Arun\_Sankar](https://discuss.elastic.co/u/Arun_Sankar)\
**Post date:** [May 27, 2013, 8:01am UTC](https://discuss.elastic.co/t/problem-creating-elasticsearch-client-under-apache-tomcat-7/10370/9 "2013-05-27T08:01:58Z")

</div>

Hi,  
any news here ?  
Please help  
Arun

---

<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, 2:34am UTC](https://discuss.elastic.co/t/problem-creating-elasticsearch-client-under-apache-tomcat-7/10370/10 "2017-07-06T02:34:39Z")

</div>


