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 =
·
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,那只能退而求其次,通过手动的方式注入
更多推荐
已为社区贡献7条内容
所有评论(0)