无法在elasticsearch 6.2.1中找到client.indices()。putMapping(putMappingRequest)

时间:2018-02-21 07:04:00

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

我试图在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插入映射的任何其他方法

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

您的链接指向未发布版本的文档。对于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);