我在AWS上运行了一个ES实例,我希望使用JAVA API连接到它。
TransportClient client = TransportClient.builder().build()
.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9320));
List<DiscoveryNode> nodes = client.connectedNodes();
System.out.println(nodes.size()); // prints 0
for (DiscoveryNode node : nodes) {
System.out.println(node.toString());
}
SearchRequestBuilder searchRequestBuilder = client.prepareSearch("indexName");
String postQuery = "{ some stuff }";
searchRequestBuilder.setQuery(QueryBuilders.wrapperQuery(postQuery));
SearchResponse searchResponse = searchRequestBuilder.execute().actionGet();
System.out.println(searchResponse.toString().replace("\n\n", "\n"));
当我运行这个程序时,我得到:
NoNodeAvailableException [没有配置的节点可用:
[{#运输#-1} {127.0.0.1} {本地主机/ 127.0.0.1:9320}]
我已经隧道进入TCP端口为9320
且REST端口为9220
的实例。
animesh$ lsof -i :9320
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
ssh 44239 animesh 7u IPv6 ______ 0t0 TCP localhost:9320 (LISTEN)
ssh 44239 animesh 8u IPv4 ______ 0t0 TCP localhost:9320 (LISTEN)
animesh$ curl localhost:9220
{
"name" : "SuperNode",
"cluster_name" : "SuperCluster",
"version" : {
"number" : "2.3.0",
"build_hash" : "8371be8d5fe5df7fb9c0516c474d77b9feddd888",
"build_timestamp" : "2016-03-29T07:54:48Z",
"build_snapshot" : false,
"lucene_version" : "5.5.0"
},
"tagline" : "You Know, for Search"
}
答案 0 :(得分:0)
此案例的结帐清单是: