elasticsearch-dump 迁移es数据 (elasticdump)

elasticsearch部分查询语句

复制代码

# 获取集群的节点列表:
curl ‘localhost:9200/_cat/nodesv’

列出所有索引:

curl ‘localhost:9200/_cat/indicesv’

创建一个名为“customer”的索引,然后再查看所有的索引:
curl -X PUT ‘localhost:9200/customerpretty’
curl ‘localhost:9200/_cat/indicesv’

复制代码

参考链接:https://blog.csdn.net/pilihaotian/article/details/52452014

github地址 :https://github.com/taskrabbit/elasticsearch-dump

或者 :https://www.npmjs.com/package/elasticdump

复制代码

wget https://nodejs.org/dist/v8.11.2/node-v8.11.2-linux-x64.tar.xz

tar xf node-v8.11.2-linux-x64.tar.xz

mv node-v8.11.2-linux-x64 /usr/local

ln -s /usr/local/node-v8.11.2-linux-x64/bin/npm /usr/local/bin/npm

ln -s /usr/local/node-v8.11.2-linux-x64/bin/node /usr/local/bin/node

npm init -f

npm install elasticdump

#因为我只用一次,所以这里没有安装到全局,需要到node_modules目录下才能找到 elasticdump , 我安装的位置如下:

/usr/local/node-v8.11.2-linux-x64/node_modules/elasticdump/bin/elasticfump

复制代码

数据迁移:

复制代码

'#拷贝analyzer分词
elasticdump
–input=http://production.es.com:9200/my_index
–output=http://staging.es.com:9200/my_index
–type=analyzer
'#拷贝映射
elasticdump
–input=http://production.es.com:9200/my_index
–output=http://staging.es.com:9200/my_index
–type=mapping
'#拷贝数据
elasticdump
–input=http://production.es.com:9200/my_index
–output=http://staging.es.com:9200/my_index
–type=data

复制代码

复制代码

# 注意 elasticdump 提供给了–httpAuthFile 参数来做认证
–httpAuthFile When using http auth provide credentials in ini file in form
`user=
password=`

只需要写一个ini文件 ,文件中写入用户名和密码就可以了

这里其实还有另外一个好的方法

在–input参数和–output参数的的url中添加账号密码

例如

elasticdump
–input=http://prod-username:prod-passowrd@production.es.com:9200/my_index
–output=http://stage-username:stage-password@staging.es.com:9200/my_index
–type=data

复制代码

如果网络情况不好,或者没有网络还可以先备份到文件:

复制代码

# 备份索引数据到文件里:
elasticdump
–input=http://production.es.com:9200/my_index
–output=/data/my_index_mapping.json
–type=mapping
elasticdump
–input=http://production.es.com:9200/my_index
–output=/data/my_index.json
–type=data

备份到标准输出,且进行压缩(这里有一个需要注意的地方,我查询索引信息有6.4G,用下面的方式备份后得到一个789M的压缩文件,这个压缩文件解压后有19G):

elasticdump
–input=http://production.es.com:9200/my_index
–output=$
| gzip > /data/my_index.json.gz

把一个查询结果备份到文件中

elasticdump
–input=http://production.es.com:9200/my_index
–output=query.json
–searchBody ‘{“query”:{“term”:{“username”: “admin”}}}’

复制代码

elasticdump还是非常方便的,主要是可以指定查询条件,把查询结果进行备份。如果按照日期进行查询,那么就可以迁移指定之间段内的数据,

恢复数据

# 将备份文件的数据导入ES
elasticdump
–input=./data.json
–output=http://es.com:9200

其实对ES了解还很少,中间可能有问题,还需要学习,就目前的了解程度,不保证上面的步骤完整,只是给大家一个大概的思路。

程度,不保证上面的步骤完整,只是给大家一个大概的思路。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值