Elasticsearch 报错:elasticsearch Received message from unsupported version: [6.4.3] minimal spring data elasticsearch [6.8.0] 时间: 2019-10-12 17:55 分类: JAVA 前面一片文章关于`Elasticsearch 7.x`单机部署是没问题了,发现`Spring data elastcsearch`在使用的时候还是报了标题中的错误。 这个错误不是`Spring boot`应用程序报的(报的那个错误不太好找原因),于是查看`elasticsearch`日志,发现报错: ``` elasticsearch Received message from unsupported version: [6.4.3] minimal spring data elasticsearch [6.8.0] ``` 这样一来错误信息就比较明显了,就是说`srping data elasticsearch`那边的`elasticsearch`jar包版本太低了,至少是`6.8.0`才行,于是去查看`pom.xml`依赖,果然是`6.4.3`版本。 那么,如何解决?提高`Spring data elasticsearch`版本?结果发现最高版本的`Spring data elasticsearch`内置引用的`elasticsearch`依赖还是`6.4.3`的。 没办法了吗?肯定不是的,`Spring Cloud`给我们提供了自定义依赖版本的方法,原文如下: ``` 91.3 Customize Dependency Versions If you use a Maven build that inherits directly or indirectly from spring-boot-dependencies (for instance, spring-boot-starter-parent) but you want to override a specific third-party dependency, you can add appropriate elements. Browse the spring-boot-dependencies POM for a complete list of properties. For example, to pick a different slf4j version, you would add the following property: 1.7.5 [Note] Doing so only works if your Maven project inherits (directly or indirectly) from spring-boot-dependencies. If you have added spring-boot-dependencies in your own dependencyManagement section with import, you have to redefine the artifact yourself instead of overriding the property. [Warning] Each Spring Boot release is designed and tested against this specific set of third-party dependencies. Overriding versions may cause compatibility issues. To override dependency versions in Gradle, see this section of the Gradle plugin’s documentation. ``` 那么,问题就很好解决了,于是在`pom.xml`增加如下配置: ``` 6.8.0 ``` 一开始我改的是`7.3`的`elasticsearch`版本,结果发现`spring data elasticsearch`使用时会报错,说找不到某某方法,不用多想,肯定是`elasticsearch`版本不兼容,我这里遇到的就是`getTotalHits()`低版本返回的是`hits`的个数,`7.3`版本返回结果是个对象还要调用`getTotalHits().value`获取。 总之就是版本兼容问题,改成最低需求`6.8`版本,问题解决。 标签: elasticsearch spring-data-elasticsearch