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

标签 elasticsearch

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

I don't care about old data What 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 mapping If 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/

相关文章:

java - 当我们在tomcat服务器中替换为新的PKI时,SSL证书错误

laravel - 如何将流明日志发送到 ELK

elasticsearch - 为什么 NEST 包括 TCP 保持事件状态?

c# - 接口(interface)上带有嵌套 ElasticType 的 ElasticSearch

elasticsearch - Liferay在Kibana的时区名称是什么?

elasticsearch - ElasticSearch查询DSL组合术语和通配符

Elasticsearch - 在同一嵌套范围内聚合多个字段

c# - 如何使用值名称获取重复值的计数

elasticsearch - Elasticsearch查询以查找术语数量等于指定数量的文档

jdbc - java.sql.SQLException:<field_name>的验证失败: 'null'无法强制转换为double类型