elasticsearch,google-compute-engine,Java,elasticsearch,Google Compute Engine" /> elasticsearch,google-compute-engine,Java,elasticsearch,Google Compute Engine" />

Java Elasticsearch 5.1.2中的NoNodeAvailableException[所有配置的节点均不可用]

Java Elasticsearch 5.1.2中的NoNodeAvailableException[所有配置的节点均不可用],java,elasticsearch,google-compute-engine,Java,elasticsearch,Google Compute Engine,在Google Compute Engine上,我创建了3个虚拟机,并在其上安装了Elasticsearch 5.1.2。 我为单播发现安装了GCE发现插件 从我的本地web浏览器(Win7),我可以成功访问这些Elasticsearch节点。 在Google云平台上,我添加了接受tcp:9300、tcp:9200的防火墙规则 现在我想使用Java transport client与本地Java应用程序中的远程Elasticsearch节点进行对话。 我确信cluster.name是正确的 代码

在Google Compute Engine上,我创建了3个虚拟机,并在其上安装了
Elasticsearch 5.1.2
。 我为单播发现安装了
GCE发现插件

从我的本地web浏览器(Win7),我可以成功访问这些Elasticsearch节点。 在Google云平台上,我添加了接受tcp:9300、tcp:9200的防火墙规则

现在我想使用Java transport client与本地Java应用程序中的远程Elasticsearch节点进行对话。 我确信
cluster.name
是正确的

代码和错误如下所示:

public class NativeClient {

    @SuppressWarnings({ "resource", "unchecked" })
    public static Client createTransportClient() throws UnknownHostException {

        Settings settings = Settings.builder().put("cluster.name", "elasticsearch").put("client.transport.sniff", true)
                .build();

        TransportClient client = new PreBuiltTransportClient(settings)
                .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("104.100.100.96"), 9300));

        return client;
    }

    private final Node node = null;
    private final Client client = null;
}


public class IndicesOperations {
    private final Client client;

    public IndicesOperations(Client client) {
        this.client = client;
    }

    public boolean checkIndexExists(String name){
        IndicesExistsResponse response=client.admin().indices().prepareExists(name).execute().actionGet();
        return response.isExists();
    }

    public static void main( String[] args ) throws InterruptedException, UnknownHostException {
        Client client =NativeClient.createTransportClient();
        IndicesOperations io=new IndicesOperations(client);
        String myIndex = "test";
        if(io.checkIndexExists(myIndex))
            io.deleteIndex(myIndex);
        io.createIndex(myIndex);
        Thread.sleep(1000);
        io.closeIndex(myIndex);
        io.openIndex(myIndex);
        io.deleteIndex(myIndex);
    }
}


Exception in thread "main" NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{lu8DzekbSWOrNEgFgXxpgQ}{104.100.100.96}{104.100.100.96:9300}]]
    at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:328)
    at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:226)
    at org.elasticsearch.client.transport.TransportProxyClient.execute(TransportProxyClient.java:59)
    at org.elasticsearch.client.transport.TransportClient.doExecute(TransportClient.java:345)
    at org.elasticsearch.client.support.AbstractClient.execute(AbstractClient.java:403)
    at org.elasticsearch.client.support.AbstractClient$IndicesAdmin.execute(AbstractClient.java:1226)
    at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:80)
    at org.elasticsearch.action.ActionRequestBuilder.execute(ActionRequestBuilder.java:54)
    at com.packtpub.IndicesOperations.checkIndexExists(IndicesOperations.java:16)
    at com.packtpub.IndicesOperations.main(IndicesOperations.java:49)
elasticsearch.yml

network.host: _gce_

cloud:
  gce:
      project_id: es-cloud
      zone: asia-east1-b
discovery:
      type: gce
编辑

在google compute engine上部署java应用程序后,它可以访问在google compute engine上运行的elasticsearch实例。在这个应用程序中,我刚刚修改了
InetAddress.getByName(“10.140.0.2”)
。在本地机器上部署时,我使用了该虚拟机的
外部ip


我还需要修改什么才能在本地机器上运行它?

我将虚拟机的
外部ip
附加到
网络中。在elasticsearch.yml中发布\u host
属性,然后我可以访问远程虚拟机上运行的elasticsearch:

network.host: _gce_
network.publish_host: 104.100.100.96

cloud:
  gce:
      project_id: es-cloud
      zone: asia-east1-b
discovery:
      type: gce
我不太明白,但幸运的是它起作用了