使用curl创建ElasticSearch索引出现映射解析错误如何解决
问题排查结论
- 你使用的是Elasticsearch 7.x及更高版本,该版本默认取消了对自定义文档类型的支持,仅保留内置的
_doc单类型,你在mapping中定义的athlete属于不被支持的自定义类型,触发根因报错 - 你使用的
string字段类型早已在Elasticsearch 5.x版本被废弃,需要替换为text或者keyword类型
修复后的执行命令
curl -X PUT "http://localhost:9200/my-index-000002?pretty" -H 'Content-Type: application/json' -d' { "mappings": { "properties": { "birthdate": { "type": "date", "format": "dateOptionalTime" }, "location": { "type": "geo_point" }, "name": { "type": "text" }, "rating": { "type": "integer" }, "sport": { "type": "text" } } } }'
补充说明
如果name、sport字段需要做精确匹配、分组聚合或者排序操作,可以将类型替换为keyword;dateOptionalTime是当前date类型的默认支持格式,无需显式声明也可以正常使用。
内容的提问来源于stack exchange,提问作者Timothy Clotworthy
相关产品推荐
相关产品推荐

