[英]Unable to update index with mapping in Elasticsearch 7.x
我正在尝试按照此资源更新现有索引中的映射,但出现错误:
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "mapper [NAME] cannot be changed from type [text] to [keyword]"
}
],
"type": "illegal_argument_exception",
"reason": "mapper [NAME] cannot be changed from type [text] to [keyword]"
},
"status": 400
}
以下是我要提出的要求:
curl -X PUT \
http://localhost:9200/company/_mapping \
-H 'cache-control: no-cache' \
-H 'content-type: application/json' \
-H 'postman-token: a8384316-7374-069c-05e5-5be4e0a8f6d8' \
-d '{
"dynamic": "strict",
"properties": {
"NAME": {
"type": "keyword"
},
"DOJ": {
"type": "date"
}
}
}'
我知道我可以使用新映射重新创建索引,但为什么我不能更新现有的?
您无法更改现有字段的映射,您需要使用正确的映射创建新索引,然后重新索引您的数据
除支持的映射参数外,您无法更改现有字段的映射或字段类型。 更改现有字段可能会使已编入索引的数据无效。
此线程中的注释是正确的,因为将text
字段更改为keyword
字段将被视为映射中断更改(并引发“无法从 [type] 更改为 [type]”异常)。
text
映射扩展为包含keyword
的多字段映射:curl -X PUT \
http://localhost:9200/company/_mapping \
-H 'content-type: application/json' \
-d '{
"dynamic": "strict",
"properties": {
"NAME": {
"type": "text",
"fields": {
"keyword": { <---
"type": "keyword"
}
}
},
"DOJ": {
"type": "date"
}
}
}'
完成此调整后,您可以通过空白Update by query调用轻松获取此新属性:
curl -X PUT \
http://localhost:9200/company/_update_by_query \
-H 'content-type: application/json'
最后,您可以在查询中定位NAME.keyword
。 好消息是,您也将保留原始text
。
你能指定名字吗? 它发生在我身上,因为 NAME 包含一个点(例如“histological.group”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.