Elasticsearch版本:
1.7.1
故障
執行新建Index命令:PUT /hrms
報錯:
{
"error": "MapperParsingException[mapping [candidate]]; nested: MapperParsingException[
Root type mapping not empty after parsing! Remaining fields: [experience : {type=float}
]]; ",
"status": 400
}
原因分析
難道是Index已經存在嗎?於是嘗試刪除Index:
DELETE /hrms
報錯:Index不存在?!
{
"error": "IndexMissingException[[hrms] missing]",
"status": 404
}
創建Index,報錯信息中的“Remaining fields: [experience : {type=float}]”十分詭異,原因查找了很久,原來是之前創建的Index Templates沒有刪除。
PUT /_template/hrms-template
{
"template": "hrms*",
"mappings": {
"candidate": {
"experience": {
"type": "float"
}
}
}
}
解決方案
執行以下命令刪除Index templates即可:DELETE /_template/hrms-template
總結
Index templates有點類似於數據庫中的觸發器,會被隱蔽地自動執行,再加上ES報錯不夠清晰,因此容易引發一些問題。