前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >java.lang.NoSuchMethodError: org.elasticsearch.action.support.master.AcknowledgedResponse

java.lang.NoSuchMethodError: org.elasticsearch.action.support.master.AcknowledgedResponse

作者头像
程裕强
发布2019-08-01 14:56:53
2.1K0
发布2019-08-01 14:56:53
举报

参考官方教程

代码语言:javascript
复制
<dependency>
            <groupId>org.elasticsearch.client</groupId>
            <artifactId>elasticsearch-rest-high-level-client</artifactId>
            <version>7.2.0</version>
</dependency>
代码语言:javascript
复制
package com.example.restclient;

import org.apache.http.HttpHost;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.support.master.AcknowledgedResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import java.io.IOException;


public class DeleteIndex {
    static RestHighLevelClient client = new RestHighLevelClient(
            RestClient.builder(
                    new HttpHost("localhost", 9200, "http")));

    public static void main(String[] agrs) throws IOException {
        // 1、创建请求参数
        DeleteIndexRequest request = new DeleteIndexRequest("test");
        // 2. 执行删除操作
        AcknowledgedResponse deleteIndexResponse = client.indices().delete(request, RequestOptions.DEFAULT);
        // 3、处理响应
        boolean acknowledged = deleteIndexResponse.isAcknowledged();
        System.out.println("acknowledged = " + acknowledged);
        //4.关闭RestHighLevelClient
        client.close();

    }
}

报错,找不到方法

代码语言:javascript
复制
Exception in thread "main" java.lang.NoSuchMethodError: org.elasticsearch.action.support.master.AcknowledgedResponse.fromXContent(Lorg/elasticsearch/common/xcontent/XContentParser;)Lorg/elasticsearch/action/support/master/AcknowledgedResponse;
	at org.elasticsearch.client.IndicesClient.delete(IndicesClient.java:97)
	at com.example.restclient.DeleteIndex.main(DeleteIndex.java:26)

国外用户也遇到类似的错误 https://stackoverflow.com/questions/53755092/i-got-a-java-lang-nosuchmethoderror-when-using-deleteindexrequest

解决办法,

增加一个依赖即可

代码语言:javascript
复制
        <dependency>
            <groupId>org.elasticsearch</groupId>
            <artifactId>elasticsearch</artifactId>
            <version>7.2.0</version>
        </dependency>

看来Elasticsearch 7.x的官方文档坑还是很多的

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
原始发表:2019年07月16日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
相关产品与服务
Elasticsearch Service
腾讯云 Elasticsearch Service(ES)是云端全托管海量数据检索分析服务,拥有高性能自研内核,集成X-Pack。ES 支持通过自治索引、存算分离、集群巡检等特性轻松管理集群,也支持免运维、自动弹性、按需使用的 Serverless 模式。使用 ES 您可以高效构建信息检索、日志分析、运维监控等服务,它独特的向量检索还可助您构建基于语义、图像的AI深度应用。
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档