【问题标题】:unable to find client.indices().putMapping(putMappingRequest) in elasticsearch 6.2.1无法在 elasticsearch 6.2.1 中找到 client.indices().putMapping(putMappingRequest)
【发布时间】:2018-07-31 16:20:25
【问题描述】:

我试图在 elasticsearch 6.2.1 的 RestHighLevelClient 中插入映射

从下面的链接中我找到了以下插入映射的代码

https://www.elastic.co/guide/en/elasticsearch/client/java-rest/master/java-rest-high-put-mapping.html

    RestHighLevelClient client =  new RestHighLevelClient(RestClient.builder(new HttpHost(ipaddress, port, "http")));
    client.indices().putMapping(putMappingRequest);

但我在 client.indices() 中找不到 putMapping(putMappingRequest)

这是我在项目中添加的maven依赖

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

谁能帮我找出适合我要求的正确 jar 文件或使用 RestHighLevelClient 插入映射的任何其他方式

非常感谢任何帮助。

【问题讨论】:

    标签: java elasticsearch maven-dependency node-rest-client


    【解决方案1】:

    您的链接指向未发布版本的文档。对于 6.2.1,您需要使用 CreateIndexRequest,如下所示:

    CreateIndexRequest request = new CreateIndexRequest("twitter"); 
    request.mapping("tweet", 
        "  {\n" +
        "    \"tweet\": {\n" +
        "      \"properties\": {\n" +
        "        \"message\": {\n" +
        "          \"type\": \"text\"\n" +
        "        }\n" +
        "      }\n" +
        "    }\n" +
        "  }", 
        XContentType.JSON);
    CreateIndexResponse createIndexResponse = client.indices().create(request);
    

    【讨论】:

    • 感谢@Val,但我也找不到 client.indices().exists(request) 你能提出任何替代方案吗
    • 您应该查看的文档是 elastic.co/guide/en/elasticsearch/client/java-rest/current/… 。该版本尚不支持 exists 方法。
    • 能否推荐支持rest高阶客户端的elasticsearch版本和文档
    • 很遗憾,您请求的功能尚未发布。不过,它可能会进入 ES 6.3。同时,您可以使用low-level REST client 来实现您想要的效果
    • 酷,很高兴它有帮助!
    猜你喜欢
    • 2018-08-02
    • 2021-10-18
    • 2017-03-25
    • 1970-01-01
    • 1970-01-01
    • 2020-12-18
    • 2020-02-04
    • 2015-02-10
    • 1970-01-01
    相关资源
    最近更新 更多