近期在Spring boot中对Elastic Search进行了简单的集成,参照了官方文档,文档推荐的是使用java rest client进行数据库访问,内容写的还是比较清楚的。
文档地址
依赖:
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>7.3.1</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>7.3.1</version>
</dependency>
但在部署后使用时出现报错:
java.lang.NoSuchMethodError: org.elasticsearch.client.Request.addParameters(Ljava/util/Map;)V
at org.elasticsearch.client.IndicesRequestConverters.indicesExist(IndicesRequestConverters.java:481) ~[elasticsearch-rest-high-level-client-7.3.1.jar:7.3.1]
at org.elasticsearch.client.RestHighLevelClient.internalPerformRequest(RestHighLevelClient.java:1450) ~[elasticsearch-rest-high-level-client-7.3.1.jar:7.3.1]
at org.elasticsearch.client.RestHighLevelClient.performRequest(RestHighLevelClient.java:1439) ~[elasticsearch-rest-high-level-client-7.3.1.jar:7.3.1]
at org.elasticsearch.client.IndicesClient.exists(IndicesClient.java:784) ~[elasticsearch-rest-high-level-client-7.3.1.jar:7.3.1]
接下来查看源码,发现Request的addParameters需要传递的参数位(String,String),而调用时传递的为Map。
后来bing搜了一下,发现有人遇到了同样的问题。
elasticsearch的issue
其实很简单,在Spring boot中需要显式地使用一些传递依赖项,因为Spring boot声明了6.4版的es:
<properties>
<elasticsearch.version>7.3.1</elasticsearch.version>
</properties>
网友评论