How to name the type of a mapping with RHLC 6.7.0

I have a code to create a mapping on an existing index with the RHLC 6.7.0.
I'd like to give a name to this mapping. I understand that types are going to diasppear but does it mean that a mapping will always be called _doc ?
There is a method .type() for the PutMappingRequest in the javadoc (https://www.javadoc.io/doc/org.elasticsearch/elasticsearch/6.7.0) but it seems that it's not shipped with the package...
Maven dependancy :

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

Code to put a mapping :

    Map<String, Object> name = new HashMap<>();
    name.put("type", "text");
    name.put("analyzer", "custom_analyzer");
    name.put("search_analyzer", "custom_analyzer");

    Map<String, Object> description = new HashMap<>();
    description.put("type", "text");
    description.put("analyzer", "custom_analyzer");
    description.put("search_analyzer", "custom_analyzer");

    Map<String, Object> properties = new HashMap<>();
    properties.put("name", name);
    properties.put("description", description);

    Map<String, Object> mappingSource = new HashMap<>();
    mappingSource.put("properties", properties);

    PutMappingRequest requestMapping = new PutMappingRequest(indexName);
    requestMapping.source(mappingSource);

    AcknowledgedResponse putMappingResponse = 
    client.indices().putMapping(requestMapping, RequestOptions.DEFAULT);

I can't write

requestMapping.type("mytype");

Hmmm. That sounds right. Apparently type(String) has not been implemented in 6.7 and marked as deprecated at the same time. Which would be a bit weird to add a deprecated method.

I guess that when you are using this API you should just ignore the type whatever API you are calling then.

Is that an issue for your use case?

I think it's not only for 6.7 but also for 7.x.
It's not a big problem, I can stick with the default _doc name for the mapping, but a custom name would would me more clear.

EDIT.
And I forgot to add that when using

    IndexRequest indexRequest = new IndexRequest(indexName, "_doc")
    .id("1").source(doc);

I have to set the type _doc or I get an error:

[WARNING] 
java.lang.reflect.InvocationTargetException
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:297)
    at java.lang.Thread.run (Thread.java:748)
Caused by: org.elasticsearch.action.ActionRequestValidationException: Validation Failed: 1: type is missing;
    at org.elasticsearch.action.ValidateActions.addValidationError (ValidateActions.java:26)
    at org.elasticsearch.action.index.IndexRequest.validate (IndexRequest.java:155)
    at org.elasticsearch.client.RestHighLevelClient.performRequest (RestHighLevelClient.java:1730)
    at org.elasticsearch.client.RestHighLevelClient.performRequestAndParseEntity (RestHighLevelClient.java:1696)
    at org.elasticsearch.client.RestHighLevelClient.index (RestHighLevelClient.java:928)
    at com.test.ElasticClient.insertDocument (ElasticClient.java:191)
    at com.test.App.main (App.java:13)
    at sun.reflect.NativeMethodAccessorImpl.invoke0 (Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke (NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke (DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke (Method.java:498)
    at org.codehaus.mojo.exec.ExecJavaMojo$1.run (ExecJavaMojo.java:297)
    at java.lang.Thread.run (Thread.java:748)

I just tried with 6.7.2 with:

client.index(new IndexRequest("test", "_doc").id("1").source("{\"foo\":\"bar\"}", XContentType.JSON), RequestOptions.DEFAULT);

This works well. I'd recommend upgrading.

Ok, but you have to specify the mapping type, which is _doc. Maybe I misunderstood your last comment, you suggested to ignore the type, but it must be specified. I'll try all this with 7.x, but it's still not clear to me if it's possible to give a custom name to the mapping when using the RHLC, for whatever version superior to 6.7.

I misread your previous answer I'm afraid.

I'll test that again hopefully tomorrow and update.

Thanks for your help, but I thought about it and it's not that important, it's ok to have a predefined mapping name, it changes nothing. :slight_smile:

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.