如何使用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

相关推荐
洛森唛20 小时前
Elasticsearch DSL 查询语法大全:从入门到精通
后端·elasticsearch
字节跳动数据平台1 天前
代码量减少 70%、GPU 利用率达 95%:火山引擎多模态数据湖如何释放模思智能的算法生产力
大数据
得物技术1 天前
深入剖析Spark UI界面:参数与界面详解|得物技术
大数据·后端·spark
武子康1 天前
大数据-238 离线数仓 - 广告业务 Hive分析实战:ADS 点击率、购买率与 Top100 排名避坑
大数据·后端·apache hive
武子康2 天前
大数据-237 离线数仓 - Hive 广告业务实战:ODS→DWD 事件解析、广告明细与转化分析落地
大数据·后端·apache hive
大大大大晴天2 天前
Flink生产问题排障-Kryo serializer scala extensions are not available
大数据·flink
Elasticsearch3 天前
如何使用 Agent Builder 排查 Kubernetes Pod 重启和 OOMKilled 事件
elasticsearch
Elasticsearch4 天前
通用表达式语言 ( CEL ): CEL 输入如何改进 Elastic Agent 集成中的数据收集
elasticsearch
武子康4 天前
大数据-236 离线数仓 - 会员指标验证、DataX 导出与广告业务 ODS/DWD/ADS 全流程
大数据·后端·apache hive
武子康5 天前
大数据-235 离线数仓 - 实战:Flume+HDFS+Hive 搭建 ODS/DWD/DWS/ADS 会员分析链路
大数据·后端·apache hive