# How to name the type of a mapping with RHLC 6.7.0

**URL:** <https://discuss.elastic.co/t/how-to-name-the-type-of-a-mapping-with-rhlc-6-7-0/180358>\
**Category:** Elasticsearch\
**Created:** [May 9, 2019, 12:02pm UTC](https://discuss.elastic.co/t/how-to-name-the-type-of-a-mapping-with-rhlc-6-7-0/180358 "2019-05-09T12:02:32Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![key](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/key/32/45480_2.png) [@key](https://discuss.elastic.co/u/key)\
**Post date:** [May 9, 2019, 12:02pm UTC](https://discuss.elastic.co/t/how-to-name-the-type-of-a-mapping-with-rhlc-6-7-0/180358/1 "2019-05-09T12:02:32Z")

</div>

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](https://www.javadoc.io/doc/org.elasticsearch/elasticsearch/6.7.0)) but it seems that it's not shipped with the package...  
Maven dependancy :

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

```

Code to put a mapping :

```auto
    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

```auto
requestMapping.type("mytype");

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 9, 2019, 4:04pm UTC](https://discuss.elastic.co/t/how-to-name-the-type-of-a-mapping-with-rhlc-6-7-0/180358/2 "2019-05-09T16:04:48Z")

</div>

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.

> <https://github.com/elastic/elasticsearch/blob/3ce7d2c9b621e796ace43008134413cea7648a06/client/rest-high-level/src/test/java/org/elasticsearch/client/documentation/IndicesClientDocumentationIT.java#L435-L516>

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?

---

<div class="post-metadata">

**Author:** ![key](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/key/32/45480_2.png) [@key](https://discuss.elastic.co/u/key)\
**Post date:** [May 9, 2019, 5:04pm UTC](https://discuss.elastic.co/t/how-to-name-the-type-of-a-mapping-with-rhlc-6-7-0/180358/3 "2019-05-09T17:04:23Z")

</div>

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

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

```

I have to set the type _\_doc_ or I get an error:

```auto
[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)

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 9, 2019, 8:36pm UTC](https://discuss.elastic.co/t/how-to-name-the-type-of-a-mapping-with-rhlc-6-7-0/180358/4 "2019-05-09T20:36:18Z")

</div>

I just tried with 6.7.2 with:

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

```

This works well. I'd recommend upgrading.

---

<div class="post-metadata">

**Author:** ![key](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/key/32/45480_2.png) [@key](https://discuss.elastic.co/u/key)\
**Post date:** [May 9, 2019, 8:59pm UTC](https://discuss.elastic.co/t/how-to-name-the-type-of-a-mapping-with-rhlc-6-7-0/180358/5 "2019-05-09T20:59:37Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [May 9, 2019, 9:12pm UTC](https://discuss.elastic.co/t/how-to-name-the-type-of-a-mapping-with-rhlc-6-7-0/180358/6 "2019-05-09T21:12:42Z")

</div>

I misread your previous answer I'm afraid.

I'll test that again hopefully tomorrow and update.

---

<div class="post-metadata">

**Author:** ![key](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/key/32/45480_2.png) [@key](https://discuss.elastic.co/u/key)\
**Post date:** [May 9, 2019, 9:26pm UTC](https://discuss.elastic.co/t/how-to-name-the-type-of-a-mapping-with-rhlc-6-7-0/180358/7 "2019-05-09T21:26:58Z")

</div>

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. 🙂

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [June 6, 2019, 9:26pm UTC](https://discuss.elastic.co/t/how-to-name-the-type-of-a-mapping-with-rhlc-6-7-0/180358/8 "2019-06-06T21:26:59Z")

</div>

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