elasticsearch将数据导出json文件【使用elasticdump】

一、前提准备

须要使用npm安装,还未安装的朋友能够阅读另外一篇个人博客《安装使用npm》,windows环境。npm

二、安装es-dump

打开终端窗口PowerShell或者cmd。json

输入命令,等待安装:-g 表示全局安装(可选)。windows

npm install elasticdump -g

三、备份数据

须要更详尽的解释,也能够查看官方文档。"\"不表明换行,参数命令直接在后面加空格隔开。app

[cpp]  view plain  copy

  1. #拷贝数据,能够是分词拷贝,能够是映射拷贝,也能够是全数据拷贝  
  2. elasticdump \  
  3.   --input=http://production.es.com:9200/my_index \  
  4.   --output=http://staging.es.com:9200/my_index \  
  5.   --type=analyzer  
  6. elasticdump \  
  7.   --input=http://production.es.com:9200/my_index \  
  8.   --output=http://staging.es.com:9200/my_index \  
  9.   --type=mapping  
  10. elasticdump \  
  11.   --input=http://production.es.com:9200/my_index \  
  12.   --output=http://staging.es.com:9200/my_index \  
  13.   --type=data  

也能够拷贝成json文件进行数据输出:spa

[cpp]  view plain  copy

  1. elasticdump \  
  2.   --input=http://production.es.com:9200/my_index \  
  3.   --output=/data/my_index_mapping.json \  
  4.   --type=mapping  
  5. elasticdump \  
  6.   --input=http://production.es.com:9200/my_index \  
  7.   --output=/data/my_index.json \  
  8.   --type=data  

也可进行压缩拷贝或者根据查询自定字段进行部分数据导出:.net

[cpp]  view plain  copy

  1. # Backup and index to a gzip using stdout:   
  2. elasticdump \  
  3.   --input=http://production.es.com:9200/my_index \  
  4.   --output=$ \  
  5.   | gzip > /data/my_index.json.gz  
  6.    
  7. # Backup the results of a query to a file   
  8. elasticdump \  
  9.   --input=http://production.es.com:9200/my_index \  
  10.   --output=query.json \  
  11.   --searchBody '{"query":{"term":{"username": "admin"}}}'  

elasticdump比较灵活的一点是,一样的,变换input output内容,一样能够实现数据导入工做。blog

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值