admin

Elasticsearch 报错:elasticsearch Received message from unsupported version: [6.4.3] minimal spring data elasticsearch [6.8.0]
前面一片文章关于Elasticsearch 7.x单机部署是没问题了,发现Spring data elastcse...
扫描右侧二维码阅读全文
12
2019/10

Elasticsearch 报错:elasticsearch Received message from unsupported version: [6.4.3] minimal spring data elasticsearch [6.8.0]

前面一片文章关于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那边的elasticsearchjar包版本太低了,至少是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 <properties> 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:

<properties>
    <slf4j.version>1.7.5<slf4j.version>
</properties>
[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 <scope>import</scope>, 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增加如下配置:

<properties>
        <elasticsearch.version>6.8.0</elasticsearch.version>
    </properties>

一开始我改的是7.3elasticsearch版本,结果发现spring data elasticsearch使用时会报错,说找不到某某方法,不用多想,肯定是elasticsearch版本不兼容,我这里遇到的就是getTotalHits()低版本返回的是hits的个数,7.3版本返回结果是个对象还要调用getTotalHits().value获取。

总之就是版本兼容问题,改成最低需求6.8版本,问题解决。

Last modification:October 12th, 2019 at 05:55 pm
If you think my article is useful to you, please feel free to appreciate

Leave a Comment