# Elastic search create Index is failing

**URL:** <https://discuss.elastic.co/t/elastic-search-create-index-is-failing/163843>\
**Category:** Elasticsearch\
**Created:** [January 11, 2019, 5:55am UTC](https://discuss.elastic.co/t/elastic-search-create-index-is-failing/163843 "2019-01-11T05:55:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ganil.89](https://avatars.discourse-cdn.com/v4/letter/g/85f322/32.png) [@ganil.89](https://discuss.elastic.co/u/ganil.89)\
**Post date:** [January 11, 2019, 5:55am UTC](https://discuss.elastic.co/t/elastic-search-create-index-is-failing/163843/1 "2019-01-11T05:55:08Z")

</div>

I am trying to create index with High Rest Client, version 6.5.0

CreateIndexRequest createIndexRequest = new CreateIndexRequest();  
createIndexRequest.index(indexName);  
createIndexRequest.settings(source, XContentType.JSON);  
createIndexRequest.mapping(indexType, source, XContentType.JSON);  
createIndexRequest.source(source, XContentType.JSON);  
try {  
client.indices().create(createIndexRequest, RequestOptions.DEFAULT);  
} catch (IOException e) {  
e.printStackTrace();  
}  
I am getting error as -\> **java.lang.IllegalStateException: mappings for type "books" were already defined**

Did I made any mistake?

---

<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:** [January 11, 2019, 7:12am UTC](https://discuss.elastic.co/t/elastic-search-create-index-is-failing/163843/2 "2019-01-11T07:12:25Z")

</div>

Delete the index first before creating it.  
Otherwise this will conflict.

---

<div class="post-metadata">

**Author:** ![ganil.89](https://avatars.discourse-cdn.com/v4/letter/g/85f322/32.png) [@ganil.89](https://discuss.elastic.co/u/ganil.89)\
**Post date:** [January 11, 2019, 7:59am UTC](https://discuss.elastic.co/t/elastic-search-create-index-is-failing/163843/3 "2019-01-11T07:59:37Z")

</div>

Actually there is no index in ES, its not even reaching to insert part, actually the error is thrown from createIndexRequest.source(source, XContentType.JSON);

1. When createIndexRequest.mapping(indexType, source, XContentType.JSON); is executed, the source is put in to map with key as indexType
2. When createIndexRequest.source(source, XContentType.JSON); is executed, in the api internal call, it is trying to put the source in to map with same key.

Please find below trace:

java.lang.IllegalStateException: mappings for type "taggings" were already defined

```
at org.elasticsearch.action.admin.indices.create.CreateIndexRequest.mapping(CreateIndexRequest.java:264)
at org.elasticsearch.action.admin.indices.create.CreateIndexRequest.source(CreateIndexRequest.java:394)
at org.elasticsearch.action.admin.indices.create.CreateIndexRequest.source(CreateIndexRequest.java:375)
at org.elasticsearch.action.admin.indices.create.CreateIndexRequest.source(CreateIndexRequest.java:346)
```

---

<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:** [February 8, 2019, 7:59am UTC](https://discuss.elastic.co/t/elastic-search-create-index-is-failing/163843/4 "2019-02-08T07:59:38Z")

</div>

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