【发布时间】:2019-12-16 20:01:11
【问题描述】:
Elastic Search 配置如下:
import java.net.InetAddress;
@Configuration
@EnableElasticsearchRepositories
public class ElasticSearchConfig {
@Value("localhost")
private String host;
@Value("9300")
private int port;
@Value("elasticsearch")
private String clusterName;
@Bean
public Client client() throws Exception {
Settings esSettings = Settings.builder()
.put("cluster.name", clusterName)
.put("node.name", "node-1")
.put("node.attr.rack","r1")
.put("client.transport.sniff", true)
.build();
TransportClient transportClient = new PreBuiltTransportClient(esSettings);
transportClient.addTransportAddress(new TransportAddress(InetAddress.getByName(host),port));
return transportClient;
}
/* @Bean
public ElasticsearchOperations elasticsearchTemplate() throws Exception {
return new ElasticsearchTemplate(client());
}*/
}
我收到以下异常:
NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}{6cirTCG_SJW0yPPONMB-HQ}{localhost}{127.0.0.1:9300}]]
at org.elasticsearch.client.transport.TransportClientNodesService.ensureNodesAreAvailable(TransportClientNodesService.java:349)
at org.elasticsearch.client.transport.TransportClientNodesService.execute(TransportClientNodesService.java:247)
at org.elasticsearch.client.transport.TransportProxyClient.execute(TransportProxyClient.java:60)
at
请推荐
我尝试启用所有不同的属性,例如 client.transport.sniffing、node.attr.rack 等。我在 elasticsearch.yml 中启用了所有这些属性
【问题讨论】:
-
为什么要创建传输客户端,可以使用高级别的客户端吗?/
-
端口 9300 用于 ES 节点通信。我们应该使用 9200 与 Elasticsearch 交互。
-
您的集群是如何设置的?以及您使用哪个版本的弹性搜索?它是否在本地主机和端口 9300 上运行?您使用哪个版本的 Spring Data Elasticsearch?
-
@SathishkumarRakkiasamy 9300 也适用于使用传输客户端,尽管它在 ES 7 中已被弃用,但仍然可用。
标签: spring-boot elasticsearch spring-data-elasticsearch