# Questions on migrating 8.2 for templates in Java

**URL:** <https://discuss.elastic.co/t/questions-on-migrating-8-2-for-templates-in-java/305507>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [May 24, 2022, 1:15pm UTC](https://discuss.elastic.co/t/questions-on-migrating-8-2-for-templates-in-java/305507 "2022-05-24T13:15:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Raushan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/raushan/32/102180_2.png) [@Raushan](https://discuss.elastic.co/u/Raushan)\
**Post date:** [May 24, 2022, 1:15pm UTC](https://discuss.elastic.co/t/questions-on-migrating-8-2-for-templates-in-java/305507/1 "2022-05-24T13:15:05Z")

</div>

Hi, I'm migrating from elastic client 7.5.2 to 8.2. From HLRC to RestClient  
I used to create Index template like this:

```auto
PutIndexTemplateRequest request = new PutIndexTemplateRequest(templateName);
        request.source(template, XContentType.JSON);
        AcknowledgedResponse putTemplateResponse = null;
        try {
            putTemplateResponse = restClient.indices().putTemplate(request, RequestOptions.DEFAULT);
            putTemplateResponse.isAcknowledged();
            return putTemplateResponse.isAcknowledged();
        } catch (IOException e) {
            log.error(e);
        }

```

Questions:

1. What is difference between [PutTemplateRequest (java-client 8.2.0 API)](https://artifacts.elastic.co/javadoc/co/elastic/clients/elasticsearch-java/8.2.0/co/elastic/clients/elasticsearch/indices/PutTemplateRequest.html) and [PutIndexTemplateRequest (java-client 8.2.0 API)](https://artifacts.elastic.co/javadoc/co/elastic/clients/elasticsearch-java/8.2.0/co/elastic/clients/elasticsearch/indices/PutIndexTemplateRequest.html) ?  
I see both doing same.

2. I'm using [PutTemplateRequest (java-client 8.2.0 API)](https://artifacts.elastic.co/javadoc/co/elastic/clients/elasticsearch-java/8.2.0/co/elastic/clients/elasticsearch/indices/PutTemplateRequest.html)  
and my template creation fails. I'm using `withJson` to pass template json.  
**Error** :

```auto
[es/indices.put_template] failed: [mapper_parsing_exception] Failed to parse mapping: dynamic template [remark] has invalid content [{"path_match":"*.*remark*","mapping":{"copy_to":["all"],"type":"object"}}], attempted to validate it with the following match_mapping_type: [object, string, long, double, boolean, date, binary]

```

**2.a** What's wrong with the request?  
**2.b** I tried in Kibana dev tools with same JSON... `PUT /_template/eua-cdb1_core_efk_8`

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/5/8/58334c0b42d83ddd8cb285afbb2f7a9e38b5ec84.png)

It is success. How come ??

One Last Question 🙂  
It says `#! Legacy index templates are deprecated in favor of composable templates.`  
Which latest Java method should we use ?

\*\*NOTE: Some template creation got success with similar JSON structure.

Please help me with the information or examples

---

<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 21, 2022, 1:15pm UTC](https://discuss.elastic.co/t/questions-on-migrating-8-2-for-templates-in-java/305507/2 "2022-06-21T13:15:35Z")

</div>

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