[英]Changing field type of an index to new index in Elasticsearch
lets say that I have index that its mapping look like this:假设我有索引,它的映射如下所示:
curl -XPUT 'http://localhost:9200/oldindex/_mapping/book' -d '
{
"book" : {
"properties" : {
"title" : {"type" : "text"},
"words" : {"type" : "text"},
"pages": {"type": "int"}
}
}
}'
I want to create a new index from the old index, but now I want the "words" type field to be "keyword" instead of "text":我想从旧索引创建一个新索引,但现在我希望“words”类型字段是“keyword”而不是“text”:
curl -XPUT 'http://localhost:9200/oldindex/_mapping/book' -d '
{
"book" : {
"properties" : {
"title" : {"type" : "text"},
"words" : {"type" : "keyword"},
"pages": {"type": "int"}
}
}
}'
How can I do that?我该怎么做? can I use "Reindex API" or there is a better solution?我可以使用“Reindex API”还是有更好的解决方案?
Assuming you don't want another field like wordsKeyword
on the index, the Reindex API would probably be best.假设您不希望索引上有其他字段,如wordsKeyword
,那么wordsKeyword
API 可能是最好的。 Move your data to a temp index, nuke the index and recreate it (with an updated mapping), then reindex the temp index data back into the new index.将您的数据移动到临时索引,取消索引并重新创建它(使用更新的映射),然后将临时索引数据重新索引到新索引中。
Step by step this is:一步一步是:
If you don't mind having another field and don't want to reindex, you could look into using the _update_by_query API to literally copy over the value into the newly mapped keyword
field via a script, thereby deprecating the text
one.如果您不介意拥有另一个字段并且不想重新索引,您可以考虑使用_update_by_query API 通过脚本将值逐字复制到新映射的keyword
字段中,从而弃用text
字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.