Put mapping fails index_already_exists_exception

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 and here 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}
1 Like

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.

When I read the 2.3 doc 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.

1 Like

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.

I've opened a pull request to clarify this in the docs.