0

我有一个在 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[配置的节点都不可用:
[{#transport#-1}{127.0.0.1}{localhost/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"
}
4

1 回答 1

0

我的这种情况下的结帐清单是:

  • 客户端和服务器版本可以不同
  • 集群名称可以不同
  • 访问主机和端口时可能存在网络问题。
于 2016-05-20T20:42:17.813 回答