1、前情提要:
https://www.elastic.co/guide/en/elasticsearch/client/java-api-client/current/installation.html
以上是Elasticsearch對接Java的官方文件(pom依賴部分)
我本地Windows安裝的Elasticsearch也是8.15.3版本
2、啟動報錯
***************************
APPLICATION FAILED TO START
***************************
Description:
An attempt was made to call a method that does not exist. The attempt was made from the following location:
co.elastic.clients.transport.rest_client.SafeResponseConsumer.<clinit>(SafeResponseConsumer.java:52)
The following method did not exist:
org.elasticsearch.client.RequestOptions$Builder.setHttpAsyncResponseConsumerFactory(Lorg/elasticsearch/client/HttpAsyncResponseConsumerFactory;)Lorg/elasticsearch/client/RequestOptions$Builder;
The method's class, org.elasticsearch.client.RequestOptions$Builder, is available from the following locations:
jar:file:/C:/repository/java/org/elasticsearch/client/elasticsearch-rest-client/6.4.3/elasticsearch-rest-client-6.4.3.jar!/org/elasticsearch/client/RequestOptions$Builder.class
It was loaded from the following location:
file:/C:/repository/java/org/elasticsearch/client/elasticsearch-rest-client/6.4.3/elasticsearch-rest-client-6.4.3.jar
Action:
Correct the classpath of your application so that it contains a single, compatible version of org.elasticsearch.client.RequestOptions$Builder
報錯翻譯:大意是指正在呼叫一個不存在的method,這個method對應的class在我的本地maven倉庫的xxx路徑,並提到了elasticsearch-rest-client的版本,給出的建議是糾正該client的唯一性&相容性……
我Google了一下報錯內容,在Elasticsearch官網中找到了一個類似的issue,官方給出的回答是elasticsearch-rest-client版本不對,但是那個issue最後並未被髮起者確認解決問題,而是在一段時間後自動關閉了。
3、依賴分析
發現官方推薦的依賴中整合的elasticsearch-rest-client版本是6.4.3而非8.15.3
因此嘗試手動新增elasticsearch-rest-client8.15.3版本的依賴
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-client</artifactId>
<version>8.15.3</version>
</dependency>
再次啟動專案,啟動成功。
起初我以為是阿里映象中上傳的elasticsearch-java依賴有誤,在除錯過程中,我嘗試把maven的settings.xml檔案中的阿里映象替換成Apache倉庫,發現仍然存在該問題,因此可以確定應該是官方製作依賴時留下的bug?