# Put mapping fails index\_already\_exists\_exception

**URL:** <https://discuss.elastic.co/t/put-mapping-fails-index-already-exists-exception/56782>\
**Category:** Elasticsearch\
**Created:** [July 29, 2016, 11:04pm UTC](https://discuss.elastic.co/t/put-mapping-fails-index-already-exists-exception/56782 "2016-07-29T23:04:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![vchav73](https://avatars.discourse-cdn.com/v4/letter/v/f475e1/32.png) [@vchav73](https://discuss.elastic.co/u/vchav73)\
**Post date:** [July 29, 2016, 11:04pm UTC](https://discuss.elastic.co/t/put-mapping-fails-index-already-exists-exception/56782/1 "2016-07-29T23:04:38Z")

</div>

I am trying to add a mapping for a new type to an existing index in ES 2.3.3. I'm following he the examples from [here](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html) and [here](https://www.elastic.co/blog/changing-mapping-with-zero-downtime) but keep getting the result seen below. Any idea why this is generating an error?

```
[root@vm mappings]# curl -X PUT http://localhost:9200/production-2016.07.19 -d '{"mappings":{"new_type":{"properties":{"new_field":{"type":"string"}}}}}'
{"error":{"root_cause":[{"type":"index_already_exists_exception","reason":"already exists","index":"production-2016.07.19"}],"type":"index_already_exists_exception","reason":"already exists","i
ndex":"production-2016.07.19"},"status":400}
```

---

<div class="post-metadata">

**Author:** ![Glen\_Smith](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/glen_smith/32/111656_2.png) [@Glen\_Smith](https://discuss.elastic.co/u/Glen_Smith)\
**Post date:** [July 30, 2016, 6:56pm UTC](https://discuss.elastic.co/t/put-mapping-fails-index-already-exists-exception/56782/2 "2016-07-30T18:56:50Z")

</div>

The problem is, that, as the error says, the index already exists.

See the doc page in your first link. The API call you are using is for defining the mapping when creating a new index. Use the other examples, for adding a type to an existing index.

---

<div class="post-metadata">

**Author:** ![vchav73](https://avatars.discourse-cdn.com/v4/letter/v/f475e1/32.png) [@vchav73](https://discuss.elastic.co/u/vchav73)\
**Post date:** [July 30, 2016, 7:09pm UTC](https://discuss.elastic.co/t/put-mapping-fails-index-already-exists-exception/56782/3 "2016-07-30T19:09:41Z")

</div>

When I read [the 2.3 doc](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-put-mapping.html) on this I see this:

> The PUT mapping API allows you to add a new type to an existing index, or new fields to an existing type:

It then lists these three examples:

> PUT twitter  
> {  
> "mappings": {  
> "tweet": {  
> "properties": {  
> "message": {  
> "type": "string"  
> }  
> }  
> }  
> }  
> }

> PUT twitter/\_mapping/user  
> {  
> "properties": {  
> "name": {  
> "type": "string"  
> }  
> }  
> }

> PUT twitter/\_mapping/tweet  
> {  
> "properties": {  
> "user\_name": {  
> "type": "string"  
> }  
> }  
> }

To me, this implies that any of the three examples would all you to add a new type to an existing index. I now know, since I've tried the other two examples, that only the last two will add a new type to an existing index. At least to me, the doc is inconsistent with the observed behavior.

---

<div class="post-metadata">

**Author:** ![Glen\_Smith](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/glen_smith/32/111656_2.png) [@Glen\_Smith](https://discuss.elastic.co/u/Glen_Smith)\
**Post date:** [July 30, 2016, 7:15pm UTC](https://discuss.elastic.co/t/put-mapping-fails-index-already-exists-exception/56782/4 "2016-07-30T19:15:51Z")

</div>

The first example has a notation (1).

Immediately below the examples, note (1) says:

> Creates an index called twitter with the message field in the tweet mapping type.

I'll concede that you may have a point about the documentation. I hope, though, that now your understanding of how that API behaves is cleared up, and you can use the appropriate endpoint to accomplish your design goals.

---

<div class="post-metadata">

**Author:** ![Glen\_Smith](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/glen_smith/32/111656_2.png) [@Glen\_Smith](https://discuss.elastic.co/u/Glen_Smith)\
**Post date:** [July 30, 2016, 7:19pm UTC](https://discuss.elastic.co/t/put-mapping-fails-index-already-exists-exception/56782/5 "2016-07-30T19:19:50Z")

</div>

I've opened [a pull request](https://github.com/elastic/elasticsearch/pull/19703) to clarify this in the docs.

---

<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 5, 2017, 10:31pm UTC](https://discuss.elastic.co/t/put-mapping-fails-index-already-exists-exception/56782/6 "2017-07-05T22:31:32Z")

</div>


