【问题标题】:How to update elasticsearch field type如何更新弹性搜索字段类型
【发布时间】:2015-01-16 21:59:29
【问题描述】:

我需要将 elasticsearch 字段类型整数更新为 long 我尝试了以下方法,但它不起作用

curl -XPUT 'http://localhost:9200/testwork/_mapping/message?ignore_conflicts=true' -d '
{
    "message" : {
        "properties" : {
            "status" : {"type" : "long"}
        }
    }
}
'

在没有 ignore_conflicts 参数的情况下尝试时会出现类似错误

{"error":"MergeMappingException[Merge failed with failures {[mapper [status] of different type, current_type [integer], merged_type [long]]}]","status":400}

但在使用 ignore_conflicts 参数时没有得到错误得到类似的响应

{"acknowledged":true} 

但是状态字段的类型没有改变。请帮我这样做

【问题讨论】:

    标签: node.js elasticsearch


    【解决方案1】:

    如果您有数据,则无法更改数据类型。

    您必须删除您的索引,使用您想要的数据类型创建映射,然后重新索引您的数据。


    要重新索引,您需要导出和重新导入数据 - 有一些工具(扫描和滚动和批量 API)可以让这更容易,请参阅 reindexing your data

    另一种方法是创建一个新索引,然后使用aliasing - 即在对最新索引执行插入写入时(可以使用其中包含单个索引的别名),但是在执行查询时,从包含所有相关索引(索引的新旧版本)的别名。

    【讨论】:

    • 感谢您的快速回复。如何备份现有数据?所以我可以在重新索引集合后恢复备份数据。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多