gpt4 book ai didi

java - org.elasticsearch.transport.NodeDisconnectedException : [][inet[localhost/127. 0.0.1:9300]][cluster/nodes/info] 断开连接

转载 作者:行者123 更新时间:2023-11-30 06:08:06 27 4
gpt4 key购买 nike

我是 Elastic Search Java Api[5.0] 的新手。我正在使用elasticsearch-5.0.0。我尝试使用 Spring Boot 创建一个 Java 应用程序(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”。我需要帮助通过正确检测原因来解决我的问题。

最佳答案

尝试使用 5.0 文档中提到的 PreBuiltTransportClient:

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

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

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

The client must have the same major version (e.g. 2.x, or 5.x) as the nodes in the cluster. Clients may connect to clusters which have a different minor version (e.g. 2.3.x) but it is possible that new functionality may not be supported. Ideally, the client should have the same version as the cluster.

https://www.elastic.co/guide/en/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}]

关于java - org.elasticsearch.transport.NodeDisconnectedException : [][inet[localhost/127. 0.0.1:9300]][cluster/nodes/info] 断开连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40429631/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com