天天看點

ES 報錯 java.lang.NoSuchMethodError:...IndicesOptions.ignoreThrottled() 的解決方案

原文位址:http://www.5ixiudou.com/portal/detailInfo/1000000005/291

ES 報錯 java.lang.NoSuchMethodError: org.elasticsearch.action.support.IndicesOptions.ignoreThrottled()Z 的解決方案

一。基本情景

ES版本:7.2.0

任務描述:springboot 整合 ES。

出現的問題:NoSuchMethodError: xxx

二。問題分析

springboot整合有兩種方式:

一種通過 spring-boot-starter-data-elasticsearch 的依賴,但是目前沒有對較新的ES的支援。

ES 報錯 java.lang.NoSuchMethodError:...IndicesOptions.ignoreThrottled() 的解決方案

第二種是通過 elasticsearch-rest-high-level-client 的依賴。這種,支援新版本的ES的支援。

本人就是使用的這種方式:報錯的時候,引入的依賴如下:

ES 報錯 java.lang.NoSuchMethodError:...IndicesOptions.ignoreThrottled() 的解決方案

在根據網上的springboot整合ES的教程,代碼實作之後,發現運作報錯 java.lang.NoSuchMethodError: org.elasticsearch.action.support.IndicesOptions.ignoreThrottled()Z ,這時,第一感覺是jar包不對,或者沖突了。然後檢視網上的資料,有人說是 7.2.0的bug,然後把依賴降級到 7.1.1或者7.0.0就好了。試了下,沒有效果。然後各種找資料,沒有解決。最後,重新開始研究整合,才發現是缺少了依賴。。。

正确的依賴引入如下:

<dependency>

    <groupId>org.elasticsearch</groupId>

    <artifactId>elasticsearch</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.client</groupId>

    <artifactId>elasticsearch-rest-high-level-client</artifactId>

    <exclusions>

        <exclusion>

            <groupId>org.elasticsearch</groupId>

            <artifactId>elasticsearch</artifactId>

        </exclusion>

        <exclusion>

            <groupId>org.elasticsearch.client</groupId>

            <artifactId>elasticsearch-rest-client</artifactId>

        </exclusion>

    </exclusions>

    <version>7.2.0</version>

</dependency>

如果引入的依賴缺少了,就會報NoSuchMethodError的錯。

三。問題總結

缺少了依賴的引入。應該引入3個依賴,結果隻引入了 elasticsearch-rest-high-level-client 的依賴。

使用springboot時間長了以後,習慣性的隻引入一個maven 依賴就可以了,但是,這裡,不使用starter了,就一定要将所有的依賴都引入全,否則就會出現錯誤。