# Type cannot be specified during template creation

**URL:** https://discuss.elastic.co/t/type-cannot-be-specified-during-template-creation/187525
**Category:** Elasticsearch
**Created:** [June 26, 2019, 8:59am UTC](https://discuss.elastic.co/t/type-cannot-be-specified-during-template-creation/187525 "2019-06-26T08:59:18Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![yeziblo](https://avatars.discourse-cdn.com/v4/letter/y/74df32/32.png) [@yeziblo](https://discuss.elastic.co/u/yeziblo)
#### Post date: [June 26, 2019, 8:59am UTC](https://discuss.elastic.co/t/type-cannot-be-specified-during-template-creation/187525/1 "2019-06-26T08:59:18Z")

</div>

Hi everyone,

I want to create a template using the PutIndexTemplateRequest API.  
But when the template was created, I found that the mapping.type was "\_doc".  
I try to add type in the mapping json string as follows:

{  
"mytype":{  
"properties":{  
"NAME":{  
"type":"keyword"  
},  
"AGE":{  
"type":"keyword"  
},  
"ADDRESS":{  
"type":"text"  
}  
}  
}  
}

Then I got a error:  
MapperParsingException: Failed to parse mapping [\_doc]: Root mapping definition has unsupported parameters: [imsiimei : {properties={ADDRESS={type=text}, NAME={type=keyword}, AGE={type=keyword}}}]

How can I customize the type name using JAVA Template Api?

---

<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: [June 26, 2019, 9:23am UTC](https://discuss.elastic.co/t/type-cannot-be-specified-during-template-creation/187525/2 "2019-06-26T09:23:07Z")

</div>

Types are going to be removed so you should not try to change the behavior.

---

<div class="post-metadata">

### Author: ![yeziblo](https://avatars.discourse-cdn.com/v4/letter/y/74df32/32.png) [@yeziblo](https://discuss.elastic.co/u/yeziblo)
#### Post date: [June 26, 2019, 9:29am UTC](https://discuss.elastic.co/t/type-cannot-be-specified-during-template-creation/187525/3 "2019-06-26T09:29:18Z")

</div>

Hi @dadoonet

I know the type will be removed in 7.x.

However, I am using ES 6.8 now, so I hope the value of type can be more explicit.

---

<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: [June 26, 2019, 9:30am UTC](https://discuss.elastic.co/t/type-cannot-be-specified-during-template-creation/187525/4 "2019-06-26T09:30:38Z")

</div>

Don't do it. Just use the default value.

---

<div class="post-metadata">

### Author: ![yeziblo](https://avatars.discourse-cdn.com/v4/letter/y/74df32/32.png) [@yeziblo](https://discuss.elastic.co/u/yeziblo)
#### Post date: [June 26, 2019, 9:39am UTC](https://discuss.elastic.co/t/type-cannot-be-specified-during-template-creation/187525/5 "2019-06-26T09:39:15Z")

</div>

So that's the only way I can write in my code:

BulkRequest request = new BulkRequest();  
for (Map\<String, Object\> map: mapList) {  
request.add(new IndexRequest(String.valueOf(map.get("INDEX")), "\_doc").source(map));  
}  
BulkResponse responses = client.bulk(request, RequestOptions.DEFAULT);

---

<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: [June 26, 2019, 10:04am UTC](https://discuss.elastic.co/t/type-cannot-be-specified-during-template-creation/187525/6 "2019-06-26T10:04:21Z")

</div>

That's the way to go.

In 7.x you'll write:

```auto
request.add(new IndexRequest("test").id("1").source("{\"foo\":\"bar\"}", XContentType.JSON));

```

Instead of:

```auto
request.add(new IndexRequest("test").type("_doc").id("1").source("{\"foo\":\"bar\"}", XContentType.JSON));

```

---

<div class="post-metadata">

### Author: ![yeziblo](https://avatars.discourse-cdn.com/v4/letter/y/74df32/32.png) [@yeziblo](https://discuss.elastic.co/u/yeziblo)
#### Post date: [June 26, 2019, 10:12am UTC](https://discuss.elastic.co/t/type-cannot-be-specified-during-template-creation/187525/7 "2019-06-26T10:12:54Z")

</div>

OK, Thanks!

Best regards.

---

<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: [July 24, 2019, 10:12am UTC](https://discuss.elastic.co/t/type-cannot-be-specified-during-template-creation/187525/8 "2019-07-24T10:12:58Z")

</div>

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