# How to add multiple types to an index Elasticsearch 6.4

**URL:** https://discuss.elastic.co/t/how-to-add-multiple-types-to-an-index-elasticsearch-6-4/151032
**Category:** Elasticsearch
**Created:** [October 4, 2018, 10:47am UTC](https://discuss.elastic.co/t/how-to-add-multiple-types-to-an-index-elasticsearch-6-4/151032 "2018-10-04T10:47:23Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Sanjaybg](https://avatars.discourse-cdn.com/v4/letter/s/3bc359/32.png) [@Sanjaybg](https://discuss.elastic.co/u/Sanjaybg)
#### Post date: [October 4, 2018, 10:47am UTC](https://discuss.elastic.co/t/how-to-add-multiple-types-to-an-index-elasticsearch-6-4/151032/1 "2018-10-04T10:47:23Z")

</div>

I am using Elasticsearch6.4 Java High Level REST Client.  
I am creating a index per customer and trying to add multiple types in that on demand.

My code for adding type for a module goes like this

RestHighLevelClient client = IndexUtils.getIndexClient();  
boolean exists = false;  
exists = checkIndexExists(client,request,exists);  
if(exists){  
try {  
PutMappingRequest prequest = new PutMappingRequest(indexName);  
prequest.updateAllTypes(true);  
prequest.type(indexType);  
prequest.source(jsonMap);  
client.indices().putMapping(prequest, RequestOptions.DEFAULT);  
} catch (IOException e) {  
// TODO Auto-generated catch block  
e.printStackTrace();  
}  
}else{  
CreateIndexRequest createrequest = new CreateIndexRequest(indexName);  
createrequest.mapping(mapping,XContentType.JSON);  
try {  
client.indices().create(createrequest, RequestOptions.DEFAULT);  
} catch (IOException e) {  
// TODO Auto-generated catch block  
e.printStackTrace();  
}  
}  
I am getting an exception Rejecting mapping update to [customer\_13] as the final mapping would have more than 1 type

I understand this support is removed in elasticsearch6.x, but what is the alternative way to achieve this?

---

<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: [October 4, 2018, 11:00am UTC](https://discuss.elastic.co/t/how-to-add-multiple-types-to-an-index-elasticsearch-6-4/151032/2 "2018-10-04T11:00:47Z")

</div>

Read [https://www.elastic.co/guide/en/elasticsearch/reference/6.4/removal-of-types.html](https://www.elastic.co/guide/en/elasticsearch/reference/6.4/removal-of-types.html)

---

<div class="post-metadata">

### Author: ![Sanjaybg](https://avatars.discourse-cdn.com/v4/letter/s/3bc359/32.png) [@Sanjaybg](https://discuss.elastic.co/u/Sanjaybg)
#### Post date: [October 24, 2018, 6:37am UTC](https://discuss.elastic.co/t/how-to-add-multiple-types-to-an-index-elasticsearch-6-4/151032/3 "2018-10-24T06:37:02Z")

</div>

Thank u, that was very helpful

---

<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: [November 21, 2018, 6:39am UTC](https://discuss.elastic.co/t/how-to-add-multiple-types-to-an-index-elasticsearch-6-4/151032/4 "2018-11-21T06:39:18Z")

</div>

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