org.elasticsearch.client.transport.NoNodeAvailableException

时间:2015-06-07 10:00:31

标签: java

我正在尝试构建一个简单的java程序,将一个简单的json输入到elasticsearch中。我在本地机器上运行Elasticsearch。我收到以下错误。

2015-06-07 14:57:12 INFO  plugins:118 - [Ultragirl] loaded [], sites []
2015-06-07 14:57:13 INFO  plugins:118 - [NFL Superpro] loaded [], sites []
2015-06-07 14:57:18 INFO  transport:123 - [NFL Superpro] failed to get node info for [#transport#-1][abhishek][inet[localhost/127.0.0.1:9200]], disconnecting...
org.elasticsearch.transport.ReceiveTimeoutTransportException: [][inet[localhost/127.0.0.1:9200]][cluster/nodes/info] request_id [0] timed out after [5001ms]
at org.elasticsearch.transport.TransportService$TimeoutHandler.run(TransportService.java:370)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
 Exception in thread "main" org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: []
at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:298)
at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:214)
at org.elasticsearch.client.transport.support.InternalTransportClient.execute(InternalTransportClient.java:105)
at org.elasticsearch.client.support.AbstractClient.index(AbstractClient.java:94)
at org.elasticsearch.client.transport.TransportClient.index(TransportClient.java:331)
at org.elasticsearch.action.index.IndexRequestBuilder.doExecute(IndexRequestBuilder.java:313)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:91)
at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:65)
at org.elasticsearch.demo.ElasticDemo.main(ElasticDemo.java:62)

这是我试图使用eclipse运行的代码。

public static void main(String[] args) {
    Settings settings = ImmutableSettings.settingsBuilder().put("cluster.name","prop").build();
    TransportClient transportClient = new TransportClient(settings);
    Client client = new TransportClient().addTransportAddress(new InetSocketTransportAddress("localhost",9200));    

    client.prepareIndex("kod", "article", "2").setSource(putJsonDocument("abhishek sachan", "JSSATE", "Sachan4894", new String[]{"computer"}, "elasticsearch")).execute().actionGet();
}

private static Map<String, Object> putJsonDocument(String title, String content, String postDate, String[] tags, String author) {
    // TODO Auto-generated method stub

    Map<String, Object> jsonDocument = new HashMap<String, Object>();

    jsonDocument.put("title", title);
    jsonDocument.put("conten", content);
    jsonDocument.put("postDate", postDate);
    jsonDocument.put("tags", tags);
    jsonDocument.put("author", author);
    return jsonDocument;
}

1 个答案:

答案 0 :(得分:0)

传输客户端使用TCP端口,ES默认为9300。您使用的是9200,它是REST客户端的HTTP端口。这应该可以解决您的问题。