已删除Elasticsearch索引后,如何清除残留的映射?
问题分析与解决步骤
首先明确:Elasticsearch中,索引被删除后,其对应的映射会被彻底清除,不存在“索引已删但映射残留”的情况。你遇到的问题,本质是索引模板(Index Template)或组件模板(Component Template)自动将旧的映射配置应用到了新创建的索引上,导致报错。
错误原因拆解
你收到的报错是因为动态模板priority_sort的配置不符合Elasticsearch的验证规则:
Failed: Failed to parse mapping: dynamic template [priority_sort] has invalid content [{"match":"priority_","path_match":"doc.","mapping":{"fielddata":true,"type":"integer"}}], attempted to validate it with the following match_mapping_type: [object, string, long, double, boolean, date, binary]
核心问题是match_mapping_type的可选值中不包含integer,且path_match与match的组合使用存在逻辑冲突,导致ES无法通过映射验证。
解决步骤
排查并清理匹配的索引模板
- 执行命令列出所有索引模板,找到匹配你新索引名称的模板(模板的
index_patterns规则会匹配你的新索引名):GET _index_template - 找到包含
priority_sort动态模板的目标模板后,执行删除命令:DELETE _index_template/<你的模板名称> - 若不想删除整个模板,可修改模板中的
mappings配置,移除或修正错误的priority_sort动态模板。
- 执行命令列出所有索引模板,找到匹配你新索引名称的模板(模板的
排查组件模板(若使用)
- 部分索引模板会引用组件模板,执行命令列出所有组件模板:
GET _component_template - 若发现包含旧映射配置的组件模板,同样删除或修改对应内容:
DELETE _component_template/<你的组件模板名称>
- 部分索引模板会引用组件模板,执行命令列出所有组件模板:
重新创建索引
清理完相关模板后,再使用你修改后的映射配置创建新索引,即可避免旧配置被自动套用。
内容的提问来源于stack exchange,提问作者Rahul Kumar
相关产品推荐
相关产品推荐

