记录学习Elasticsearch的坑!
在用Spring Data Elasticsearch进行java对Elasticsearch创建索引的操作时,进行单元测试控制台报了注意的错
抛出错误 :NoNodeAvailableException[None of the configured nodes are available: [{#transport#-1}
网上查了很多博客也没有解决问题,弄了好久打开了Elasticsearch日志查看错误信息, 发现抛了以下的异常
java.lang.IllegalStateException: Received handshake message from unsupported version: [5.0.0] minimal compatible version is: [6.8.0]
at org.elasticsearch.transport.InboundDecoder.ensureVersionCompatibility(InboundDecoder.java:210) ~[elasticsearch-7.10.2-SNAPSHOT.jar:7.10.2-SNAPSHOT]
at org.elasticsearch.transport.InboundDecoder.readHeader(InboundDecoder.java:177) ~[elasticsearch-7.10.2-SNAPSHOT.jar:7.10.2-SNAPSHOT]
......
又根据抛出的这个异常进行全网搜索,最后查到了原因,是之前用的springBoot版本已经不支持 elasticsearch 7.x(我的是elasticsearch 7.10.8, SpringBoot 版本 是2.1.2的)
注意⚠️SpringBoot是2.2.0.RELEASE才兼容elasticsearch 7.x
马上进行对pom文件SpringBoot的版本进行修改
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.0.RELEASE</version>
<relativePath/>
</parent>
改成 2.2.0.RELEASE
再进行单元测试,发现绿了[旺柴]