springboot集成elasticsearch-rest-high-level-client的坑

我使用的是Elasticsearch7.2.0,因爲官網上推薦使用elasticsearch-rest-high-level-client端集成在springboot因此嘗試爬坑。html

首先直接引入官網的配置文件java

<dependency>
		    <groupId>org.elasticsearch.client</groupId>
		    <artifactId>elasticsearch-rest-high-level-client</artifactId>
		    <version>7.2.0</version>
		</dependency>

而後在運行時報錯:spring

...
...
Caused by: java.lang.ClassNotFoundException: org.elasticsearch.common.xcontent.DeprecationHandler
...
...

百度了一下說jar裏的Elasticsearch版本有錯,要移除了再從新引入,因此把配置文件改爲下面的樣子springboot

<dependency>
		    <groupId>org.elasticsearch.client</groupId>
		    <artifactId>elasticsearch-rest-high-level-client</artifactId>
		    <version>7.2.0</version>
		    <exclusions>
	       <exclusion>
	         <groupId>org.elasticsearch</groupId>
	         <artifactId>elasticsearch</artifactId>
	       </exclusion>
	     </exclusions>
		</dependency>
		
		<!-- 正確版本 -->
		<dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
            <version>7.2.0</version>
        </dependency>

而後再次啓動,Elasticsearch正常運行,可是發現spring的rest服務運行不正常,配置的Filter沒有正常運行,且不報錯。網上找了好久也沒有找到有相似錯誤的問題,後來反覆查看官網,他說elasticsearch-rest-high-level-client是基於elasticsearch-rest-client的,我就猜這個基於會不會是依賴的意思呢?bash

因而把配置改爲了這樣:elasticsearch

<dependency>
		    <groupId>org.elasticsearch.client</groupId>
		    <artifactId>elasticsearch-rest-high-level-client</artifactId>
		    <version>7.2.0</version>
		</dependency>

		<dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>elasticsearch-rest-client</artifactId>
            <version>7.2.0</version>
        </dependency>
		
		<dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
            <version>7.2.0</version>
        </dependency>

而後再次啓動,Elasticsearch正常運行,REST服務也正常,個人老天鵝,終於能夠了。rest

後來我找到了這篇文章Elasticsearch High Level REST Client,具體配置能夠參考下code

相關文章
相關標籤/搜索