I have confusion about elasticsearch mapping
First, I have a doc created with mapping request as
PUT /person
{
"mappings":{
"properties":{
"firstname":{
"type":"text"
}
}
}
}
Then, I want to add new property "lastname", to do that I PUT
PUT /person
{
"mappings":{
"properties":{
"lastname":{
"type":"text"
}
}
}
}
Unfortunately, the exception stops me
{
"error": {
"root_cause": [
{
"type": "resource_already_exists_exception",
"reason": "index [person/5TWopRJaQ3Clam2TiteuHg] already exists",
"index_uuid": "5TWopRJaQ3Clam2TiteuHg",
"index": "person"
}
],
"type": "resource_already_exists_exception",
"reason": "index [person/5TWopRJaQ3Clam2TiteuHg] already exists",
"index_uuid": "5TWopRJaQ3Clam2TiteuHg",
"index": "person"
},
"status": 400
}
It trys to tell me index existed, I could not update it.
But if I use,
PUT /person/_mapping
{
"properties":{
"lastname":{
"type":"text"
}
}
}
it works, and "lastname" is added into mapping.
What's the difference between /person/ {mappings:...}
and /person/_mapping {...}
?
They are all PUT method, shouldn't they do the same?
Or /person/ {mappings:...}
could only be used as created, and /person/_mapping {...}
is only for updating existed ones?
Not very make sense. What's the trick here?
https://www.elastic.co/guide/en/elasticsearch/reference/current/removal-of-types.html
Indices created in Elasticsearch 7.0.0 or later no longer accept a _default_ mapping. Indices created in 6.x will continue to function as before in Elasticsearch 6.x. Types are deprecated in APIs in 7.0, with breaking changes to the index creation, put mapping, get mapping, put template, get template and get field mappings APIs.
Hence, mappings support is deprecated in ES 7 and will be removed in ES 8