OpenSearch修改ignore_malformed属性失败,报resource_already_exists_exception
问题:修改Elasticsearch索引字段属性报错"resource_already_exists_exception"
操作场景
创建索引testindex001的请求:
PUT testindex001 { "mappings": { "properties": { "kubernetes": { "type": "object", "properties": { "annotation": { "type": "object", "properties": { "kubectl_kubernetes_io/restartedAt": { "type": "date", "ignore_malformed": false } } } } } } } }
尝试修改该索引中kubernetes.annotation.kubectl_kubernetes_io/restartedAt字段的ignore_malformed属性为true的请求:
PUT testindex001 { "mappings": { "properties": { "kubernetes": { "properties": { "annotation": { "properties": { "kubectl_kubernetes_io/restartedAt": { "type": "date", "ignore_malformed": true } } } } } } } }
报错信息
{ "type": "resource_already_exists_exception", "reason": "index [testindex001/_VoE6UwcTg6V-3QQ4KigDg] already exists", "index": "testindex001", "index_uuid": "_VoE6UwcTg6V-3QQ4KigDg", "status": 400 }
问题原因
你误用了创建索引的请求路径PUT testindex001来修改映射,这个请求的作用是创建新索引,当目标索引已存在时,就会触发resource_already_exists_exception错误。修改现有索引的映射需要使用专门的映射更新端点。
解决方法
将请求路径改为PUT testindex001/_mapping,请求体保持不变即可:
PUT testindex001/_mapping { "properties": { "kubernetes": { "properties": { "annotation": { "properties": { "kubectl_kubernetes_io/restartedAt": { "type": "date", "ignore_malformed": true } } } } } } }
补充说明
并非所有字段属性都能在索引创建后修改,比如字段的type属性就无法变更,但ignore_malformed属于允许后期修改的属性,所以上述操作是有效的。
内容的提问来源于stack exchange,提问作者2rok
相关产品推荐
相关产品推荐

