0

I was trying to insert mapping in the RestHighLevelClient of elasticsearch 6.2.1

From the following link I had found the following code for the insertion of mapping

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);

But I was unable to find putMapping(putMappingRequest) in the client.indices()

this is the maven dependency that I had added in the project

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

Can anyone help me to find out correct jar file that suits my requirement or any other way to insert mapping using RestHighLevelClient

Any help is really appreciated.

Raviteja Gannoju
  • 117
  • 3
  • 16

1 Answers1

0

Your link points to the documentation of an unreleased version. For 6.2.1, you need to use the CreateIndexRequest, like this:

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
  • 207,596
  • 13
  • 358
  • 360
  • thanks @Val, but I was also not able find client.indices().exists(request) can you suggest any alternative – Raviteja Gannoju Feb 21 '18 at 07:31
  • The documentation you should be looking at is https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-high-create-index.html . The exists method is not yet supported in that version. – Val Feb 21 '18 at 07:37
  • can you suggest elasticsearch version and document that supports rest high level client – Raviteja Gannoju Feb 21 '18 at 07:48
  • Unfortunately, the feature you're requesting is not yet released. It might come into ES 6.3, though. In the meantime, you can achieve what you want with the [low-level REST client](https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/java-rest-low.html) instead – Val Feb 21 '18 at 07:49