如何使用elasticdump进行elasticsearch数据还原

使用elasticsearch进行开发,生产环境不能改动,可能需要将数据从生产环境复制到测试环境。

elasticdump是实现这一功能的理想工具,可通过简单几行命令,即完成数据的复制迁移。

这里尝试基于docker版本的elasticsearch,验证elasticdump迁移复制数据的功能。

1 安装elasticdump

这里假设使用conda环境,先安装npm工具nodejs,然后安装elasticdump

conda install conda-forge::nodejs

npm install -g elasticdump

2 测试elasticdump

2.1 elasticsearch创建

采用docker创建elasticsearch,版本为8.11.3,启动命令如下所示。

为简化操作关闭安全验证,具体为xpack.security.enabled=false 。

这种操作通常应用于内部系统或开发测试环境。

docker run --name es01 -p 9200:9200 -p 8300:9300 \

-e "discovery.type=single-node" \

-e ES_JAVA_OPTS="-Xms1G -Xmx1G" \

-e xpack.security.enabled=false \

-d docker.elastic.co/elasticsearch/elasticsearch:8.11.3

es启动完成后,可通过以下命令直接验证。

curl http://localhost:9200/

2.2 创建索引

创建index,名称为index_name

curl -XPUT "https://localhost:9200/index_name"

2.3 导出数据

从现有源es dump索引数据,包括mapping数据和data数据。

假设现有es未设置ca证书、用户名、密码。

elasticdump \

--input='http://es_host:es_port/index_name' \

--output=/path/to/index_mapping.json \

--type=mapping

elasticdump \

--input='http://es_host:es_port/index_name \

--output= /path/to/index_data.json \

--type=data

2.4 导入数据

将之前导出的源es索引数据,导入本地创建的es。

命令如下

lasticdump \

--input=/path/to/index_mapping.json \

--output=http://localhost:9200/index_name \

--type=mapping

elasticdump \

--input=/path/to/index_data.json \

--output=http://localhost:9200/index_name \

--type=data

输出示例如下

Tue, 04 Nov 2025 10:09:00 GMT | starting dump

Tue, 04 Nov 2025 10:09:00 GMT | got 100 objects from source file (offset: 0)

Tue, 04 Nov 2025 10:09:00 GMT | got 100 objects from source file (offset: 100)

......

Tue, 04 Nov 2025 10:09:03 GMT | Total Writes: xxxx

Tue, 04 Nov 2025 10:09:03 GMT | dump complete

reference


elasticsearch-dump

https://github.com/elasticsearch-dump/elasticsearch-dump

【ElasticSearch】elasticdump 导入/导出数据及常见报错

https://blog.csdn.net/zzddada/article/details/121744016

Mac本地docker安装Kibana+ElasticSearch

https://blog.csdn.net/liliang199/article/details/151581138

python访问基于docker搭建的elasticsearch

https://blog.csdn.net/liliang199/article/details/151586083

Elasticsearch备份与还原:使用elasticdump

https://cloud.tencent.com/developer/article/2360111

Elasticsearch8关闭安全认证功能

https://juejin.cn/post/7203637198120878137

相关推荐
多年小白1 小时前
紫光国微(002049) 分析
大数据·科技·深度学习·ai
小杨互联网2 小时前
你的旧 Kindle 还能用,但平台说它该退休了
大数据·经验分享·科技·ai
泰迪智能科技2 小时前
高校人工智能与大数据产品体系及解决方案介绍
大数据·人工智能
沪漂阿龙2 小时前
面试题详解:Agent 记忆管理全解析——历史对话获取、摘要记忆、事实记忆、知识图谱记忆一次讲透
大数据·人工智能·知识图谱
逸Y 仙X2 小时前
文章三十一:ElasticSearch 管道聚合
java·大数据·elasticsearch·搜索引擎·全文检索
纽格立科技3 小时前
AI让广播过时,还是让广播稀缺?
大数据·服务器·人工智能·车载系统·信息与通信·传媒
一切皆是因缘际会3 小时前
AI工程化落地指南:
大数据·人工智能·机器学习·架构
闲人编程4 小时前
Agent的评估体系(AgentEval):如何判断一个Agent好坏?
大数据·人工智能·python·算法·agent·智能体·swe
hnult4 小时前
知识竞赛考试平台怎么选?2026 考试云全功能选型与实践指南
大数据·人工智能