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.
To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/526291db-fc42-4465-a41b-f99e7c5a55c1%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.