如果我按如下方式定义索引模板文件template.json:
{
"template": "types",
"mappings": {
"type1": {
"properties": {
"title": {
"type": "text"
}
}
},
"type2": {
"properties": {
"title": {
"type": "keyword"
}
}
}
}
}
并尝试发布:
curl -XPUT http://localhost:9200/_template/types -d@template.json
我得到这个回应:
{
"error" : {
"root_cause" : [
{
"type" : "illegal_argument_exception",
"reason" : "mapper [title] cannot be changed from type [keyword] to [text]"
}
],
"type" : "illegal_argument_exception",
"reason" : "mapper [title] cannot be changed from type [keyword] to [text]"
},
"status" : 400
}
我希望能够在模板中定义具有不同类型的不同字段的多个映射。
我在做什么或假设不正确?
我正在使用Elasticsearch 5.6。
最佳答案
如果这些字段具有相同的名称,则即使您使用的是5.6版(这也是允许在同一索引中使用多种映射类型的最后一个版本),它们也必须具有相同的字段类型。
如果类型title
中的type1
字段映射为text
,则类型title
中的字段type2
也需要映射为text
。
关于elasticsearch - Elasticsearch在索引模板中使用两个映射引发错误,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55304964/