一尘不染

获取org.elasticsearch.transport.NodeDisconnectedException:[] [inet [localhost / 127.0.0.1:9300]] [集群/节点/信息]已断开连接

elasticsearch

我是Elastic Search Java Api [5.0]的新手。我正在使用elasticsearch-5.0.0。我尝试用Spring
Boot创建一个Java Application(Maven)。运行应用程序后,它显示

2016-11-04 23:32:19.339  INFO 8280 --- [][generic][T#2]]      org.elasticsearch.client.transport       : [X-Ray] failed to get node info for [#transport#-1][DESKTOP-8SIPHSN][inet[localhost/127.0.0.1:9300]], disconnecting...
org.elasticsearch.transport.NodeDisconnectedException: [][inet[localhost/127.0.0.1:9300]][cluster:monitor/nodes/info] disconnected

我的配置文件是

@Configuration
public class ElasticsearchConfiguration {

  @Bean
  public Client client() {

        TransportClient client = new TransportClient();
        TransportAddress address = new  InetSocketTransportAddress("localhost",9300);
        client.addTransportAddress(address);        
        return client;
    }

}

我正在使用默认群集“ elasticsearch”。我需要帮助以适当地找出原因来解决我的问题。


阅读 1228

收藏
2020-06-22

共1个答案

一尘不染

尝试使用PreBuiltTransportClient5.0文档中提到的内容:

TransportClient client = new PreBuiltTransportClient(Settings.EMPTY)
        .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));

https://www.elastic.co/guide/zh-CN/elasticsearch/client/java-
api/current/transport-
client.html

另请注意,TransportClientfor ES版本2.x与5.x不兼容:

客户端必须具有与集群中的节点相同的主版本(例如2.x或5.x)。客户端可以连接到具有不同次要版本(例如2.3.x)的群集,但是有可能不支持新功能。理想情况下,客户端应具有与群集相同的版本。

https://www.elastic.co/guide/zh-CN/elasticsearch/client/java-
api/current/client.html

更新资料

作为连接测试,请尝试执行以下简单程序:

import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;

import java.net.InetAddress;
import java.net.UnknownHostException;

public class App {
    public static void main(String[] args) throws UnknownHostException {
        // The following settings aren't strictly necessary, because the default cluster name is "elasticsearch".
        Settings settings = Settings.builder().put("cluster.name", "elasticsearch").build();
        TransportClient client = new PreBuiltTransportClient(settings);
        client.addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("localhost"), 9300));
        System.out.println(client.connectedNodes());
    }
}

它应该打印到标准输出,如下所示:

[{luhcORJ}{luhcORJOSzSLPBeXocDsuQ}{mkTJpwIAQGuNYTHfRLqUIw}{127.0.0.1}{127.0.0.1:9300}]

2020-06-22