如果我定义索引模板文件template.json如下:
{
"template": "types",
"mappings": {
"type1": {
"properties": {
"title": {
"type": "text"
}
}
},
"type2": {
"properties": {
"title": {
"type": "keyword"
}
}
}
}
}
并尝试发布它:
curl -XPUT http://localhost:9200/_template/types [email protected]
我收到了这个回复:
{
"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
。