尝试连接到AWS上托管的ES时出现NoNodeAvailableException

时间:2016-05-20 19:57:46

标签: java elasticsearch elasticsearch-java-api

我在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"
}

1 个答案:

答案 0 :(得分:0)

此案例的结帐清单是:

  • 客户端和服务器版本可以不同
  • 群集名称可以不同
  • 访问主机和端口时可能存在网络问题。