【发布时间】:2018-06-14 00:31:52
【问题描述】:
以下代码解释了 Java 和 ElasticSearch 之间的通信
使用传输客户端。当我运行时,我得到 org.elasticsearch.nodedisconnectedException。任何给出的 Java Elasticsearch 的明确示例都将不胜感激,或者任何人都可以帮助我找到解决方案。
public static Client function() {
Settings setting = ImmutableSettings.settingsBuilder().put("cluster.name", "localtestsearch").build();
client = new TransportClient();
client = client.addTransportAddress(new InetSocketTransportAddress("localhost", 9300));
return client;
}
public static void main(String[] args) {
System.out.println("In Main Method");
try {
System.out.println("In try block");
Client client = new TransportClient()
.addTransportAddress(new InetSocketTransportAddress("localhost",
9300));
System.out.println("Connected");
client.close();
Settings settings = ImmutableSettings.settingsBuilder()
.put("client.transport.sniff", true).build();
TransportClient client1 = new TransportClient(settings);
org.elasticsearch.node.Node node = nodeBuilder().node();
System.out.println("Node " + node);
Client client = node.client();
System.out.println("calling Client from Node " + client);
node.close();
System.out.println("Node CLosed");
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
【问题讨论】:
标签: java json elasticsearch