gpt4 book ai didi

elasticsearch - 试图了解如何在不完全重建索​​引的情况下更新映射?

转载 作者:行者123 更新时间:2023-12-03 02:02:06 26 4
gpt4 key购买 nike

在此页面上:https://www.elastic.co/blog/changing-mapping-with-zero-downtime指出:

I don't care about old dataWhat if you want to change the datatype for a single field, and you don't care about the fact that the old data is not searchable? In this case, you have a few options:

Delete the mappingIf you delete the mapping for a specific type, then you can use the put_mapping API. to create a new mapping for that type in the existing index.


...
我的情况是,我有一列是一个字符串,我想将其更改为一个长字符串...根据该文档,听起来我应该能够做到:
curl -X DELETE localhost:9200/my_index/_mapping/property_to_change
然后做
curl -XPUT 'http://localhost:9200/my_index/_mapping/property_to_change' -d '
{
"my_index" : {
"properties" : {
"property_to_change" : {"type" : "long", "store" : true }
}
}
}
'
我误会吗?我真的必须麻烦创建别名吗?有没有简单的方法可以更改此属性的类型?
我发现与此主题相关的文档非常混乱和自相矛盾。例如,此页面 https://www.elastic.co/guide/en/elasticsearch/guide/current/mapping-intro.html
说:

You can specify the mapping for a type when you first create an index. Alternatively, you can add the mapping for a new type (or update the mapping for an existing type) later, using the /_mapping endpoint.


听起来像-好酷。那正是我想要做的。
但是下一段说:

Although you can add to an existing mapping, you can’t change it. If a field already exists in the mapping, the data from that field probably has already been indexed. If you were to change the field mapping, the already indexed data would be wrong and would not be properly searchable.


我以为它只是说您可以更新映射?现在它说你不能改变?太糊涂了。
任何人都可以对此有所了解吗?

最佳答案

您不能更改现有字段的映射。用Elasticsearch的话来说,类型是一类类似的文档,您可以为其添加更新的映射(这将添加新的字段映射),但不能更改该字段的现有映射。

例如,给定documents类型包含titletags字段的映射,您可以为该类型的PUT更新映射,从而为author字段添加映射,但是您无法将tags从一种类型更改为另一种类型,或者将映射选项或其他。

如果要将字段从字符串更改为长整数,则需要删除索引(或类型的映射,如果索引仅包含一种类型,则等效),使用您所需的映射,然后将数据重新索引到其中。

关于elasticsearch - 试图了解如何在不完全重建索​​引的情况下更新映射?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31304732/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com