使用RestHighLevelClient连接es时报错

官方文档中的client初始化


官方文档中的request对象创建方式

官方文档中的同步执行请求

本地maven依赖
image
本地代码:
public static void main(String ags[]) {

    RestHighLevelClient client = new RestHighLevelClient(
            RestClient.builder(
                    new HttpHost("localhost", 9200, "http")));

    IndexRequest indexRequest = new IndexRequest("blog", "java");

    Map<String, Object> blogMap = new HashMap<>();
    blogMap.put("id", "index_06");
    blogMap.put("title", "测试RestHighLevelClient连接es");
    blogMap.put("time", new Date());
    blogMap.put("mainContent", "主要内容");
    indexRequest.source(blogMap);
    try {
        IndexResponse response = client.index(indexRequest);
    } catch (Exception e){
        e.printStackTrace();
    }
    System.out.println("done");

}
报错如下:


注意:代码执行之后虽抛出异常,但程序仍处于阻塞状态!

你这个问题我怀疑是版本不一致导致的。就是编译版本和运行版本不一样。导致运行时没找到方法。

我猜测也是这样的 但是找到的参考文档有限,没找到具体解决方案,我这本地的6.0.0的es服务器已安装好了,不想再重新搞。但是resthighlevelclient对6.0的支持以及api感觉都和后面的版本不同