目录

SpringBoot 2.x 整合 ES2.x 报 failed to load elasticsearch nodes

在SpringBoot整合ES时,遇到如下错误。

1
ERROR 2075 --- [           main] .d.e.r.s.AbstractElasticsearchRepository : failed to load elasticsearch nodes : org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available:

相关配置

pom.xml部分配置

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
  <parent>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-parent</artifactId>
      <version>2.0.2.RELEASE</version>
      <relativePath/> <!-- lookup parent from repository -->
  </parent>
  <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-data-elasticsearch</artifactId>
  </dependency>

application.properties ES相关配置

1
2
spring.data.elasticsearch.repositories.enabled=true
spring.data.elasticsearch.cluster-nodes=192.168.xxx.xxx\:9300

版本

SpringBoot2.0

ES2.4

问题原因

导致一直解决不了问题的原因是这个链接显示SpringBoot2.0是兼容ES2.4的,所以我首先排除了兼容问题。

网上查找,报这个错的原因是因为IP限制,无论是修改ES的配置中network.host属性为0.0.0.0也好,我链接ES的机器的内网IP也好,都不好使

之后看到了这篇文章,我再次怀疑有可能版本兼容的问题,修改SpringBoot为1.5.9.RELEASE版本,不报错了。

这个兼容性问题,要么降级SpringBoot,要么升级ES,还是更新ES比较靠谱。

写在最后

降级是不能降级的,这辈子都不可能降级