美文网首页
ES导出导入索引及索引数据工具

ES导出导入索引及索引数据工具

作者: 机灵鬼鬼 | 来源:发表于2022-10-14 09:39 被阅读0次

背景:
1、使用postman查询出来的数据无法直接导入到es,导入es需要手动去整理查询的数据,麻烦耗时。
2、自己写一个程序去自动导出再导入,耗时较长,不经济。
3、mapping和settings都要导出一并迁移至目标服务器。

是否有一种专门用来处理es的索引导出导入的工具呢?当然有!
下载elasticdump并安装(参考官网https://www.npmjs.com/package/elasticdump)
执行导入导出操作:以索引bum_authority_collection为例

# 导出索引Mapping数据
./elasticdump --input=http://source:9200/bum_authority_collection/ --output=./bum_authority_collection.json --type=mapping
# 导出索引数据
./elasticdump --input=http://source:9200/bum_authority_collection/ --output=./bum_authority_collection_data.json --limit 1000 --type=data


#导入索引Mapping数据
./elasticdump --input=./bum_authority_collection.json --output=http://target:9200/bum_authority_collection/  --type=mapping
#导入索引数据
./elasticdump --input=./bum_authority_collection_data.json --output=http://target:9200/bum_authority_collection/ --limit 1000 --type=data

那问题来了,如果我es里索引非常多,这样一个一个去执行依然会耗时,怎么做?当然想到了shell脚本。
脚本名字为:esExportOrInput.sh

#!/bin/sh
index_name=$1
index_data=$1"_data"
index_settings=$1"_settings"
echo "开始执行"
# 导出索引Mapping数据
./elasticdump --input=http://source:9200/$index_name/ --output=./$index_name.json --type=mapping
./elasticdump --input=http://source:9200/$index_name/ --output=./$index_settings.json --type=settings

# 导出索引数据
./elasticdump --input=http://source:9200/$index_name/ --output=./$index_data.json --type=data --limit=1000

#导入索引Mapping数据
echo "执行删除目标服务的索引start:"$index_name
curl -XDELETE http://target:9200/$index_name
echo "执行删除目标服务的索引end:"$index_name
sleep 3
echo "等待三秒。。。"
./elasticdump --input=./$index_settings.json --output=http://target:9200/$index_name/  --type=settings
./elasticdump --input=./$index_name.json --output=http://target:9200/$index_name/  --type=mapping
./elasticdump --input=./$index_data.json --output=http://target:9200/$index_name/  --type=data --limit=1000
#清除生成的文件
rm -f ./$index_name.json
rm -f ./$index_settings.json
rm -f ./$index_data.json
#清除生成的文件
echo "索引"$index_name"执行完毕"

执行时候需要传递1个变量,就是索引名字index_name

温馨提示:

1、这个脚本仅仅只能在安装了elasticdump服务器上使用,脚本目录在/root/node_modules/elasticdump/bin
2、导出导入默认100条一批,可以添加--limit 每页条数 来自定义每页数量。
3、导入的时候一定要限制性settings的文件导入,在执行mapping的导入,不然会冲突,因为settings上带了uuid的唯一标识。
样例:如果我要对bum_user这个索引的数据从测试环境迁移到压测服务器target上,就这样执行命令
./esExportOrInput.sh bum_user

留个作业,可以对源服务器和目标服务器进行动态参数传递,就可以做到万能适配了,有兴趣就重写下这个脚本吧!!!

相关文章

  • ES导出导入索引及索引数据工具

    背景:1、使用postman查询出来的数据无法直接导入到es,导入es需要手动去整理查询的数据,麻烦耗时。2、自己...

  • 无标题文章

    建立索引 视图 导入 导出 备份 恢复

  • ES7学习笔记(五)动态映射

    通常情况下,我们使用ES建立索引的步骤是,先创建索引,然后定义索引中的字段以及映射的类型,然后再向索引中导入数据。...

  • oracle导出导入数据步骤

    1、导出表结构2、导出数据3、导入建表语句(不包含索引、外键等信息) 如果先创建了外键,那后面导入数据时,会...

  • 数据同步工具

    mysql ---> es 数据同步工具 数据同步工具介绍 基本介绍一下工具 DataX, 离线导入导出 Sqoo...

  • pandas使用手记

    数据的导入 数据的导出 创建测试对象 数据的查看与检查 数据的索引 我们对 DataFrame 进行选择,大抵从这...

  • ElasticSearch基础操作 - 浏览数据

    当前使用的ES版本为 7.2 1. 准备测试数据 下载 accounts.json,导入es: 查看索引列表,验证...

  • ES简单实用DSL查询

    ES版本信息 查看所有索引 查看字段类型 创建索引 删除索引 批量(_bulk)加载数据 查询数据 查询1000条...

  • elasticsearch 的 python API

    导入 es 创建索引 其中的 acknowledged 字段表示创建操作执行成功 重复创建索引,会引发 400 错...

  • ES索引管理工具curator安装

    ES索引管理工具curator curator是一个用于管理es中的索引和快照的工具。 curator是用Pyth...

网友评论

      本文标题:ES导出导入索引及索引数据工具

      本文链接:https://www.haomeiwen.com/subject/jwwqzrtx.html