Elasticsearch导入导出

安装elasticdump

es数据的导入和导出需要借助于elasticdump工具,这是一个nodejs的插件(需要安装node.js环境),安装方式直接使用 npm即可,安装指令如下:

npm install elasticdump -g

在这里插入图片描述

# 查看elasticdump是否安装正常
elasticdump --version

# 如果显示elasticdump不可用,大概率是之前重新设置过npm的本地仓库
# 查询npm本地仓库,默认在C:\Users\Administrator\AppData\Roaming\npm
npm config get prefix
# 设置本地npm仓库
npm config set prefix "D:\npm\npm_repository";
# 设置本地npm缓存放哪里
npm config set cache "D:\npm\npm_cache";

把prefix这个路径加入到系统环境变量中,方便使用命令直接运行,因为elasticdump全局安装也会安装到prefix这个路径下。

在这里插入图片描述

导出

# 注入导出的存放目录要存在,不然会报错
# 导出索引Mapping数据
elasticdump \
  --input=http://es实例IP:9200/index_name \
  --output=D:/esData/mapping.json \    # 存放目录
  --type=mapping 
# 导出索引数据(全量)
elasticdump \
  --input=http://es实例IP:9200/index_name \
  --output=D:/esData/data.json \
  --type=data
# 导出索引数据(指定条件)
elasticdump \
  --input=http://es实例IP:9200/index_name \
  --output=D:/esData/data.json \
  --limit=10000
  --searchBody={\"query\":{\"term\":{\"username\": \"admin\"}}}
  --type=data  

导出示例

# 导出mapping
elasticdump
 --input=http://localhost:9200/10000_niupi_*
 --output=D:/esData/mapping.json
 --type=mapping
# 导出数据
elasticdump 
	--input=http://localhost:9200/10000_niupi_* 
	--output=D:/esData/data.json 
	--limit=10000 
	--searchBody={\"query\":{\"match_all\":{}}} 
	--type=data

说明:
--type可以不要,默认就是data
--limit=每次批量导出数据的条数
--searchBody=设置查询条件(必须是转义后的json)

导入

# Mapping 数据导入至索引
elasticdump \
  --output=http://es实例IP:9200/index_name \
  --input=/home/indexdata/roll_vote_mapping.json \ # 导入数据目录
  --type=mapping
# ES文档数据导入至索引
elasticdump \
  --output=http:///es实例IP:9200/index_name \
  --input=/home/indexdata/roll_vote.json \ 
  --type=data

elasticsearch-dump官网传送门

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

我叫985

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值