ElasticSearch的两种迁移数据的方式

方式一 :elasticSearchDump

官网文档:elasticdump - npm

全局安装:
npm install elasticdump -g

1) 从sourceIp集群迁移数据到dstIp

elasticdump \

--input=http://sourceIp:9200/my_index \

--output=http://dstIp:9200/my_index \

--type=data

2) 迁移mapping

elasticdump \

--input=http://production.es.com:9200/my_index \

--output=http://staging.es.com:9200/my_index \

--type=mapping

3)下载数据

elasticdump \
  --input=http://production.es.com:9200/my_index \
  --output=query.json \
  --searchBody="{\"query\":{\"term\":{\"username\": \"admin\"}}}"

4)将下载的数据压缩

 elasticdump \
  --input=http://192.168.3.100:9200/doc_hit_info \
  --searchBody="{\"query\":{\"bool\":{\"must\":[{\"range\":{\"datetime\":{\"gt\":\"1451577600000\",\"lt\":\"1464710400000\"}}}]}}}" \
  --type=data \
  --output=$ \
  | gzip > /data/zjc/doc_hit_info.gz

 方式二:elasticSearch5.0以上支持reindex接口的迁移

官网文档:Reindex from a remote cluster | Elasticsearch Guide [7.13] | Elastic

1)使用前必须在新集群配置白名单

reindex.remote.whitelist: oldhost:9200

2)开始执行迁移任务,需要提前创建索引 

curl -X POST "localhost:9200/_reindex?pretty" -H 'Content-Type: application/json' -d'
{
  "source": {
    "remote": {
      "host": "http://oldhost:9200"
    },
    "index": "source",
    "query": {
      "match": {
        "test": "data"
      }
    }
  },
  "dest": {
    "index": "dest"
  }
}
'

 异步执行,返回taskID

3)通过taskID可以查询任务执行情况

GET _tasks/TASK_ID

4)向新集群迁移数据过程中,如果出现告警 ,需要杀死正在进行的迁移任务,重新设置查询条件。

参照官网文档:Task Management API | Elasticsearch Guide [6.4] | Elastic

执行下行杀死未执行完的任务

curl -X POST "localhost:9200/_tasks/oTUltX4IQMOUUVeiohTt8A:12345/_cancel?pretty"

 

两种方式的对比:

elasticSearchDump  不限制es版本,可同步迁移也可异步迁移数据,不需要配置白名单,缺少任务监控,数据量大控制不好查询条件容易内存溢出;

reindex es5.0以上新增API;可以支持从es5.0以下版本向es5.0及以上迁移,必须配置白名单,异步执行,详细的任务状态监控;速度相对更快;

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值