栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

java.lang.NoSuchMethodError: org.elasticsearch.search.SearchHits.getTotalHits().value

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

java.lang.NoSuchMethodError: org.elasticsearch.search.SearchHits.getTotalHits().value

java.lang.NoSuchMethodError: org.elasticsearch.search.SearchHits.getTotalHits().value错误
构建String Boot整合Elasticsearch7.x版本时报错

原因是版本不匹配…

版本对比
Spring Boot2.3.0以下不能够支持到ES7.x,个别调用相同时出现错误:
ES6.x版本调用:

long total = response.getHits().getTotalHits();

ES6.x版本源码如下:

public static final SearchHit[] EMPTY = new SearchHit[0];
    private SearchHit[] hits;
    public long totalHits;
    private float maxScore;
    ...
    public long getTotalHits() {
        return this.totalHits;
    }

ES7.x版本

long total = response.getHits().getTotalHits().value;

ES7.x源码:

public static final SearchHit[] EMPTY = new SearchHit[0];

    private final SearchHit[] hits;
    private final TotalHits totalHits;
    private final float maxScore;
    @Nullable
    private final SortField[] sortFields;
    @Nullable
    private final String collapseField;
    @Nullable
    private final Object[] collapsevalues;
...
@Nullable
    public TotalHits getTotalHits() {
        return totalHits;
    }
public final class TotalHits {

  public enum Relation {
    
    EQUAL_TO,
    
    GREATER_THAN_OR_EQUAL_TO
  }

  
	public final long value;

Spring官方解答

无论你在使用Spring Boot与Spring Data Elasticsearch进行整合,或者使用Spring Boot和Elasticsearch-rest-high-level-client整合都最好使用Spring Boot 2.3.x版本,不然都无法根本解决问题.

另外我的elasticsearch是7.X.0版本,Springboot就应该使用2.3.X版本
但是项目中还引入了jestClient, Springboot2.3.X不支持通过配置的方式自动注入jestClient,那只能退而求其次,通过手动的方式注入

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/358364.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号