# Getting exception in indexing data using node client

**URL:** <https://discuss.elastic.co/t/getting-exception-in-indexing-data-using-node-client/22731>\
**Category:** Elasticsearch\
**Created:** [March 18, 2015, 8:10am UTC](https://discuss.elastic.co/t/getting-exception-in-indexing-data-using-node-client/22731 "2015-03-18T08:10:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![prachicsa](https://avatars.discourse-cdn.com/v4/letter/p/f4b2a3/32.png) [@prachicsa](https://discuss.elastic.co/u/prachicsa)\
**Post date:** [March 18, 2015, 8:10am UTC](https://discuss.elastic.co/t/getting-exception-in-indexing-data-using-node-client/22731/1 "2015-03-18T08:10:56Z")

</div>

Hi,

I have used transport client before for the same cluster and same index,  
which works fine. I want to use node client now. I tried the following:

package es.code;

import org.apache.log4j.Logger;  
import org.elasticsearch.action.get.GetResponse;  
import org.elasticsearch.action.index.IndexResponse;  
import org.elasticsearch.client.Client;  
import org.elasticsearch.node.Node;

import static org.elasticsearch.node.NodeBuilder.\*;

import java.io.IOException;

public class elasticsearch {

```
private elasticsearch() {
}

public static void main(String[] args) throws IOException {
    System.out.println("Hello, World");
    Client client = null;

    Node node = nodeBuilder().clusterName("sample_test").client(true).node();
    client = node.client();
    String json = "{" +
            "\"user\":\"prachi\"," +
            "\"postDate\":\"2013-01-30\"," +
            "\"message\":\"trying out Elasticsearch\"" +
            "}";

    IndexResponse response = client.prepareIndex("estest", "testing")
            .setSource(json)
            .execute()
            .actionGet();

    System.out.println(response.getId());    
    node.close();  
}

```

}

I am getting the following exception:

Exception in thread "main" org.elasticsearch.discovery.MasterNotDiscoveredException: waited for [1m]  
at org.elasticsearch.action.support.master.TransportMasterNodeOperationAction$4.onTimeout(TransportMasterNodeOperationAction.java:164)  
at org.elasticsearch.cluster.ClusterStateObserver$ObserverClusterStateListener.onTimeout(ClusterStateObserver.java:239)  
at org.elasticsearch.cluster.service.InternalClusterService$NotifyTimeout.run(InternalClusterService.java:520)  
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)  
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)  
at java.lang.Thread.run(Thread.java:744)

What is it which I am doing wrong? If I remove client(true), the program  
runs successfully. But I don't see data in ES index.

What is the correct way to do it?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/526291db-fc42-4465-a41b-f99e7c5a55c1%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/526291db-fc42-4465-a41b-f99e7c5a55c1%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<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, 12:25am UTC](https://discuss.elastic.co/t/getting-exception-in-indexing-data-using-node-client/22731/2 "2017-07-06T00:25:59Z")

</div>


