elasticsearch官方提供了数据迁移的命令:
http://新集群:9200/_reindex/ POST
{
"source": {
"size": 5000,
"index": "test",
"type": "T_VEHICLE_HIST",
"remote": {
"host": "http://老集群:9200"
}
},
"dest": {
"index": "test"
},
"script": {
"source": "SimpleDateFormat dateFormat = new SimpleDateFormat(\"yyyy-MM-dd HH:mm:ss\");ctx._source.time=dateFormat.format(new Date(ctx._source.time))"
}
}
script脚本支持java语法
在迁移过程中,会出现下列错误
{
"error": {
"root_cause": [
{
"type": "illegal_argument_exception",
"reason": "[ip:9200] not whitelisted in reindex.remote.whitelist"
}
],
"type": "illegal_argument_exception",
"reason": "[ip:9200] not whitelisted in reindex.remote.whitelaist"
},
"status": 400
}
需要在新集群机器中增加配置
reindex.remote.whitelist: 老集群:9200
需要注意的是,在新集群中先把mapping创建好,不然老版本的字符串型数据的字段都会被强制转换为了keyword
Elasticsearch数据迁移实战
本文详细介绍使用Elasticsearch官方命令进行数据迁移的过程,包括配置远程集群白名单、解决迁移中遇到的非法参数异常,以及如何在新集群中预先创建mapping以避免数据类型转换问题。

被折叠的 条评论
为什么被折叠?



