简体   繁体   English

如何更新elasticsearch字段类型

[英]How to update elasticsearch field type

I need to update elasticsearch field type integer to long I tried the following way and it not works 我需要更新elasticsearch字段类型整数到long我尝试了以下方式,它不起作用

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

When tried without ignore_conflicts parameter it getting error like 在没有ignore_conflicts参数的情况下尝试时会出现错误

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

But not get error while using ignore_conflicts parameter got the response like 但是使用ignore_conflicts参数得到响应时不会出错

{"acknowledged":true} 

But the type not changed for status field. 但是状态字段的类型没有改变。 Please help me to do this 请帮我这样做

It is not possible to change the data type if you have data present. 如果您有数据,则无法更改数据类型。

You'll have to delete your index, create the mapping with the data type you want, and re-index your data. 您必须删除索引,使用所需的数据类型创建映射,然后重新索引数据。


To re-index you will need to export and re-import your data - there are some tools (scan&scroll and bulk API) to make this easier, see reindexing your data . 要重新编制索引,您需要导出并重新导入数据 - 有一些工具(扫描和滚动和批量API)可以使这更容易,请参阅重新编制数据索引

An alternative is to create a new index and then use aliasing - ie when doing an insert write to the latest index (could use an alias with a single index in it), but when doing a query, read from an alias that includes all relevant indexes (new and old versions of the index). 另一种方法是创建一个新索引,然后使用别名 - 即在插入时写入最新索引(可以使用带有单个索引的别名),但在执行查询时,请从包含所有相关的别名中读取索引(索引的新旧版本)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM