以下代码中的client.index(indexRequest)
来电:
public static void main(String...sdg) {
Settings s = ImmutableSettings.settingsBuilder()
.put("cluster.name","myCluster")
.build();
TransportClient client = new TransportClient(s)
.addTransportAddress(new InetSocketTransportAddress("localhost", 9300));;
try {
IndexRequest indexRequest = new IndexRequest("myindex", "pplain", "29");
indexRequest.source(makeAJsonDocument("some title", "some content");
client.index(indexRequest)
.actionGet();
} catch (Exception e)
{ System.out.println("error \n"+e);
e.printStackTrace();
} finally {client.close();
}
}
抛出以下错误:
Jul 24, 2015 3:40:56 PM org.elasticsearch.plugins.PluginsService <init>
INFO: [Ectokid] loaded [], sites []
error
org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: []
org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: []
at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:305)
at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:200)
at org.elasticsearch.client.transport.support.InternalTransportClient.execute(InternalTransportClient.java:106)
at org.elasticsearch.client.transport.support.InternalTransportClient.execute(InternalTransportClient.java:97)
at org.elasticsearch.client.support.AbstractClient.index(AbstractClient.java:97)
at org.elasticsearch.client.transport.TransportClient.index(TransportClient.java:335)
at ES.ThisPRJ.ThatClass.main(ThatClass.java:67)
我的elasticsearch.yml
看起来像这样:
cluster.name: myCluster
我在服务器和Java客户端上运行ES版本1.7.0 - 我只有一个ES安装。
把我弄出来。
我错过了什么?
注意:我看到了ElasticSearch Java API:NoNodeAvailableException: No node available和其他一些帖子。
TIA。
答案 0 :(得分:0)
您提供的代码中存在一个小编译问题,请检查您执行indexRequest.source的行,您错过了&#39;)&#39;。我使用这个代码,它对我来说很好。你能尝试一下吗?你遗漏了一些代码吗?
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
public class TestMe {
public static void main(String... sdg) {
Settings s = ImmutableSettings.settingsBuilder()
.put("cluster.name", "performance")
.build();
TransportClient client = new TransportClient(s)
.addTransportAddress(new InetSocketTransportAddress("localhost", 9300));
try {
IndexRequest indexRequest = new IndexRequest("myindex", "pplain", "29");
indexRequest.source("{\"title\":\"This is a title\"}");
client.index(indexRequest)
.actionGet();
} catch (Exception e) {
System.out.println("error \n" + e);
e.printStackTrace();
} finally {
client.close();
}
}
}
我猜您已经验证群集是否正在使用浏览器运行? http://localhost:9200