您当前的位置: 首页 >  Java

Dongguo丶

暂无认证

  • 2浏览

    0关注

    472博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

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

Dongguo丶 发布时间:2021-10-30 19:39:51 ,浏览量:2

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 {
/** How the {@link TotalHits#value} should be interpreted. */
  public enum Relation {
    /**
     * The total hit count is equal to {@link TotalHits#value}.
     */
    EQUAL_TO,
    /**
     * The total hit count is greater than or equal to {@link TotalHits#value}.
     */
    GREATER_THAN_OR_EQUAL_TO
  }

  /**
   * The value of the total hit count. Must be interpreted in the context of
   * {@link #relation}.
   */
	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,那只能退而求其次,通过手动的方式注入

关注
打赏
1638062488
查看更多评论
立即登录/注册

微信扫码登录

0.0410s