Getting exception in indexing data using node client


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.*;


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")



I am getting the following exception:

Exception in thread "main" org.elasticsearch.discovery.MasterNotDiscoveredException: waited for [1m]
at org.elasticsearch.cluster.ClusterStateObserver$ObserverClusterStateListener.onTimeout(
at org.elasticsearch.cluster.service.InternalClusterService$
at java.util.concurrent.ThreadPoolExecutor.runWorker(
at java.util.concurrent.ThreadPoolExecutor$

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
To view this discussion on the web visit
For more options, visit