1.下载导入导出软件

我们使用taskrabbit/elasticsearch-dump docker容器版

下载taskrabbit/elasticsearch-dump

地址:https://download.csdn.net/download/qq_33093289/85664719

2.安装taskrabbit/elasticsearch-dump软件

docker load -i elasticsearch-dump.tar

3.导出命令

3.1.不需要密码的

docker run --net=host --rm -ti -v /data/:/tmp taskrabbit/elasticsearch-dump --input=http://localhost:9200/hotel   --output=hotel.json   --type=data

3.2.es需要用户密码的:1.密码中的感叹号 ! 需要转义 2.导出文件在data

3.2.1导出es的data

docker run --net=host --rm -ti -v /data/:/tmp taskrabbit/elasticsearch-dump  --input=http://elastic:es123%21@127.0.0.1:9200/hotel --output=/tmp/hotel_data.json --type=data

参数说明:

1.--net=host 表示本机es导入导出,不是本机不需要该参数

2./data/:/tmp 文件夹映射,前一个是本地使用的文件夹 第二个是docker容器使用的文件夹,两个文件夹映射,导出成功后,自动从tmp文件夹导出到data文件夹

3.--output 这里使用的文件夹/tmp,实际文件放在本地的/data文件夹,因为在前面已经做了映射,所以可以读取到文件

4.--type 导出那种类型:default: data, options: [settings, analyzer, data, mapping, policy, alias, template, component_template, index_template]

注意:上面写的只是导入导出es的数据的,如果要把es的索引结构和mapping还有数据导出可以用下面方式

3.2.2导出es的mapping

docker run --net=host --rm -ti -v /data/:/tmp taskrabbit/elasticsearch-dump  --input=http://elastic:es123%21@127.0.0.1:9200/hotel --output=/tmp/hotel_mapping.json --type=mapping

3.2.3导出analyzer(没有分词就不需要)

docker run --net=host --rm -ti -v /data/:/tmp taskrabbit/elasticsearch-dump  --input=http://elastic:es123%21@127.0.0.1:9200/hotel --output=/tmp/hotel_analyzer.json --type=analyzer

4.导入命令

4.1.导入索引数据

将index_data.json文件放到/data/目录下, --input的这个/tmp指的是前面指向的临时文件夹

docker run --net=host --rm -ti -v /data/:/tmp taskrabbit/elasticsearch-dump  --input=/tmp/hotel_data.json --output=http://elastic:es123%21@127.0.0.1:9200/hotel --type=data

4.2.导入索引mapping

docker run --net=host --rm -ti -v /data/:/tmp taskrabbit/elasticsearch-dump  --input=/tmp/hotel_mapping.json --output=http://elastic:es123%21@127.0.0.1:9200/hotel --type=mapping

4.3.导入索引analyzer

docker run --net=host --rm -ti -v /data/:/tmp taskrabbit/elasticsearch-dump  --input=/tmp/hotel_analyzer.json --output=http://elastic:es123%21@127.0.0.1:9200/hotel --type=analyzer

5.指定导出文件大小

5.1.导出:系统自动分成几个文件大小

docker run --net=host --rm -ti -v /data/:/tmp taskrabbit/elasticsearch-dump  --input=http://elastic:es123%21@127.0.0.1:9200/hotel --output=/tmp/hotel_data.json --type=data --fileSize=100kb

5.2.导入:就像正常的导入一样,分别导入不同文件

docker run --net=host --rm -ti -v /data/:/tmp taskrabbit/elasticsearch-dump  --input=/tmp/hotel_data.split-0.json --output=http://elastic:es123%21@127.0.0.1:9200/hotel --type=data

docker run --net=host --rm -ti -v /data/:/tmp taskrabbit/elasticsearch-dump  --input=/tmp/hotel_data.split-1.json --output=http://elastic:es123%21@127.0.0.1:9200/hotel --type=data

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐