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