Elasticsearch的数据导出和导入操作(elasticdump工具),以及删除指定type的数据(delete-by-query插件)

Elasticseach目前作为查询搜索平台,的确非常实用方便。我们今天在这里要讨论的是如何做数据备份和type删除。我的ES的版本是2.4.1。

ES的备份,可不像MySQL的mysqldump这么方便,需要一个插件进行数据的导出和导入进行备份和恢复操作。这里要说的插件是elasticdump。

elasticdump的安装:

[root@localhost ~]# yum install elasticdump
已加载插件:fastestmirror, product-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Repodata is over 2 weeks old. Install yum-cron? Or run: yum makecache fast
base                                                                                                                                                                    | 3.6 kB  00:00:00     
cuda                                                                                                                                                                    | 2.5 kB  00:00:00     
epel/x86_64/metalink                                                                                                                                                    | 5.0 kB  00:00:00     
epel                                                                                                                                                                    | 4.3 kB  00:00:00     
extras                                                                                                                                                                  | 3.4 kB  00:00:00     
updates                                                                                                                                                                 | 3.4 kB  00:00:00     
(1/8): base/x86_64/primary_db                                                                                                                                           | 5.7 MB  00:00:00     
(2/8): epel/x86_64/group_gz                                                                                                                                             | 170 kB  00:00:00     
(3/8): epel/x86_64/updateinfo                                                                                                                                           | 830 kB  00:00:00     
(4/8): extras/x86_64/primary_db                                                                                                                                         | 102 kB  00:00:00     
(5/8): base/x86_64/group_gz                                                                                                                                             | 156 kB  00:00:01     
(6/8): updates/x86_64/primary_db                                                                                                                                        | 2.8 MB  00:00:00     
(7/8): epel/x86_64/primary_db                                                                                                                                           | 4.8 MB  00:00:01     
cuda/primary_db                FAILED                                          
http://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64/repodata/1d4cabb230a45d5f78f46ccd1b04914a98eab1b3-primary.sqlite.bz2: [Errno 12] Timeout on http://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64/repodata/1d4cabb230a45d5f78f46ccd1b04914a98eab1b3-primary.sqlite.bz2: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
正在尝试其它镜像。
cuda/primary_db                FAILED                                          
http://developer.download.nvidia.com/compute/cuda/repos/rhel7/x86_64/repodata/1d4cabb230a45d5f78f46ccd1b04914a98eab1b3-primary.sqlite.bz2: [Errno 14] curl#52 - "Empty reply from server"0 ETA 
正在尝试其它镜像。
Determining fastest mirrors
 * epel: mirrors.tuna.tsinghua.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 elasticdump.noarch.0.2.2.0-2.el7 将被 安装
--> 正在处理依赖关系 npm(request) < 3,它被软件包 elasticdump-2.2.0-2.el7.noarch 需要
--> 正在处理依赖关系 npm(async) < 2,它被软件包 elasticdump-2.2.0-2.el7.noarch 需要
--> 正在处理依赖关系 npm(request) >= 2,它被软件包 elasticdump-2.2.0-2.el7.noarch 需要
--> 正在处理依赖关系 nodejs(engine) >= 1.0.0,它被软件包 elasticdump-2.2.0-2.el7.noarch 需要
--> 正在处理依赖关系 npm(optimist),它被软件包 elasticdump-2.2.0-2.el7.noarch 需要
--> 正在处理依赖关系 npm(JSONStream),它被软件包 elasticdump-2.2.0-2.el7.noarch 需要
--> 正在处理依赖关系 /usr/bin/node,它被软件包 elasticdump-2.2.0-2.el7.noarch 需要
--> 正在检查事务
---> 软件包 nodejs.x86_64.1.6.11.1-1.el7 将被 安装
--> 正在处理依赖关系 npm = 1:3.10.10-1.6.11.1.1.el7,它被软件包 1:nodejs-6.11.1-1.el7.x86_64 需要
--> 正在处理依赖关系 libuv >= 1:1.9.1,它被软件包 1:nodejs-6.11.1-1.el7.x86_64 需要
--> 正在处理依赖关系 http-parser >= 2.7.0,它被软件包 1:nodejs-6.11.1-1.el7.x86_64 需要
--> 正在处理依赖关系 libuv.so.1()(64bit),它被软件包 1:nodejs-6.11.1-1.el7.x86_64 需要
--> 正在处理依赖关系 libhttp_parser.so.2()(64bit),它被软件包 1:nodejs-6.11.1-1.el7.x86_64 需要
---> 软件包 nodejs-async.noarch.0.0.2.10-1.el7 将被 安装
---> 软件包 nodejs-jsonstream.noarch.0.0.10.0-2.el7 将被 安装
--> 正在处理依赖关系 npm(through),它被软件包 nodejs-jsonstream-0.10.0-2.el7.noarch 需要
--> 正在处理依赖关系 npm(jsonparse),它被软件包 nodejs-jsonstream-0.10.0-2.el7.noarch 需要
---> 软件包 nodejs-optimist.noarch.0.0.4.0-1.el7 将被 安装
--> 正在处理依赖关系 npm(wordwrap) < 0.1,它被软件包 nodejs-optimist-0.4.0-1.el7.noarch 需要
--> 正在处理依赖关系 npm(wordwrap) >= 0.0.2,它被软件包 nodejs-optimist-0.4.0-1.el7.noarch 需要
---> 软件包 nodejs-request.noarch.0.2.25.0-1.el7 将被 安装
--> 正在处理依赖关系 npm(tunnel-agent) < 0.4,它被软件包 nodejs-request-2.25.0-1.el7.noarch 需要
--> 正在处理依赖关系 npm(qs) < 0.7,它被软件包 nodejs-request-2.25.0-1.el7.noarch 需要
--> 正在处理依赖关系 npm(oauth-sign) < 0.4,它被软件包 nodejs-request-2.25.0-1.el7.noarch 需要
--> 正在处理依赖关系 npm(node-uuid) < 1.5,它被软件包 nodejs-request-2.25.0-1.el7.noarch 需要
--> 正在处理依赖关系 npm(mime) < 1.3,它被软件包 nodejs-request-2.25.0-1.el7.noarch 需要
--> 正在处理依赖关系 npm(json-stringify-safe) < 5.1,它被软件包 nodejs-request-2.25.0-1.el7.noarch 需要
--> 正在处理依赖关系 npm(http-signature) < 0.11,它被软件包 nodejs-request-2.25.0-1.el7.noarch 需要
--> 正在处理依赖关系 npm(hawk) < 1.1,它被软件包 nodejs-request-2.25.0-1.el7.noarch 需要
--> 正在处理依赖关系 npm(form-data) < 0.2,它被软件包 nodejs-request-2.25.0-1.el7.noarch 需要
--> 正在处理依赖关系 npm(forever-agent) < 0.6,它被软件包 nodejs-request-2.25.0-1.el7.noarch 需要
--> 正在处理依赖关系 npm(cookie-jar) < 0.4,它被软件包 nodejs-request-2.25.0-1.el7.noarch 需要
--> 正在处理依赖关系 npm(aws-sign) < 0.4,它被软件包 nodejs-request-2.25.0-1.el7.noarch 需要
--> 正在处理依赖关系 npm(tunnel-agent) >= 0.3.0,它被软件包 nodejs-request-2.25.0-1.el7.noarch 需要
--> 正在处理依赖关系 npm(qs) >= 0.6.0,它被软件包 nodejs-request-2.25.0-1.el7.noarch 需要
--> 正在处理依赖关系 npm(oauth-sign) >= 0.3.0,它被软件包 nodejs-request-2.25.0-1.el7.noarch 需要
--> 正在处理依赖关系 npm(node-uuid) >= 1.4.0,它被软件包 nodejs-request-2.25.0-1.el7.noarch 需要
--> 正在处理依赖关系 npm(mime) >= 1.2.9,它被软件包 nodejs-request-2.25.0-1.el7.noarch 需要
--> 正在处理依赖关系 npm(json-stringify-safe) >= 5.0.0,它被软件包 nodejs-request-2.25.0-1.el7.noarch 需要
--> 正在处理依赖关系 npm(http-signature) >= 0.10.0,它被软件包 nodejs-request-2.25.0-1.el7.noarch 需要
--> 正在处理依赖关系 npm(hawk) >= 1.0.0,它被软件包 nodejs-request-2.25.0-1.el7.noarch 需要
--> 正在处理依赖关系 npm(form-data) >= 0.1.0,它被软件包 nodejs-request-2.25.0-1.el7.noarch 需要
--> 正在处理依赖关系 npm(forever-agent) >= 0.5.0,它被软件包 nodejs-request-2.25.0-1.el7.noarch 需要
--> 正在处理依赖关系 npm(cookie-jar) >= 0.3.0,它被软件包 nodejs-request-2.25.0-1.el7.noarch 需要
--> 正在处理依赖关系 npm(aws-sign) >= 0.3.0,它被软件包 nodejs-request-2.25.0-1.el7.noarch 需要
--> 正在检查事务
---> 软件包 http-parser.x86_64.0.2.7.1-5.el7_4 将被 安装
---> 软件包 libuv.x86_64.1.1.10.2-1.el7 将被 安装
---> 软件包 nodejs-aws-sign.noarch.0.0.3.0-1.el7 将被 安装
---> 软件包 nodejs-cookie-jar.noarch.1.0.3.0-1.el7 将被 安装
---> 软件包 nodejs-forever-agent.noarch.0.0.5.0-1.el7 将被 安装
---> 软件包 nodejs-form-data.noarch.0.0.1.1-1.el7 将被 安装
--> 正在处理依赖关系 npm(combined-stream) < 0.1,它被软件包 nodejs-form-data-0.1.1-1.el7.noarch 需要
--> 正在处理依赖关系 npm(combined-stream) >= 0.0.4,它被软件包 nodejs-form-data-0.1.1-1.el7.noarch 需要
---> 软件包 nodejs-hawk.noarch.0.1.0.0-1.el7 将被 安装
--> 正在处理依赖关系 npm(sntp) < 0.3,它被软件包 nodejs-hawk-1.0.0-1.el7.noarch 需要
--> 正在处理依赖关系 npm(hoek) < 0.10,它被软件包 nodejs-hawk-1.0.0-1.el7.noarch 需要
--> 正在处理依赖关系 npm(cryptiles) < 0.3,它被软件包 nodejs-hawk-1.0.0-1.el7.noarch 需要
--> 正在处理依赖关系 npm(boom) < 0.5,它被软件包 nodejs-hawk-1.0.0-1.el7.noarch 需要
--> 正在处理依赖关系 npm(sntp) >= 0.2,它被软件包 nodejs-hawk-1.0.0-1.el7.noarch 需要
--> 正在处理依赖关系 npm(hoek) >= 0.9,它被软件包 nodejs-hawk-1.0.0-1.el7.noarch 需要
--> 正在处理依赖关系 npm(cryptiles) >= 0.2,它被软件包 nodejs-hawk-1.0.0-1.el7.noarch 需要
--> 正在处理依赖关系 npm(boom) >= 0.4,它被软件包 nodejs-hawk-1.0.0-1.el7.noarch 需要
---> 软件包 nodejs-http-signature.noarch.0.0.10.0-3.el7 将被 安装
--> 正在处理依赖关系 npm(ctype) < 0.6,它被软件包 nodejs-http-signature-0.10.0-3.el7.noarch 需要
--> 正在处理依赖关系 npm(assert-plus) < 0.2,它被软件包 nodejs-http-signature-0.10.0-3.el7.noarch 需要
--> 正在处理依赖关系 npm(asn1) < 0.2,它被软件包 nodejs-http-signature-0.10.0-3.el7.noarch 需要
--> 正在处理依赖关系 npm(ctype) >= 0.5.3,它被软件包 nodejs-http-signature-0.10.0-3.el7.noarch 需要
--> 正在处理依赖关系 npm(assert-plus) >= 0.1.2,它被软件包 nodejs-http-signature-0.10.0-3.el7.noarch 需要
--> 正在处理依赖关系 npm(asn1) >= 0.1.11,它被软件包 nodejs-http-signature-0.10.0-3.el7.noarch 需要
---> 软件包 nodejs-json-stringify-safe.noarch.0.5.0.0-1.el7 将被 安装
---> 软件包 nodejs-jsonparse.noarch.0.1.0.0-2.el7 将被 安装
---> 软件包 nodejs-mime.noarch.0.1.2.11-1.el7 将被 安装
---> 软件包 nodejs-node-uuid.noarch.0.1.4.1-1.el7 将被 安装
---> 软件包 nodejs-oauth-sign.noarch.0.0.3.0-1.el7 将被 安装
---> 软件包 nodejs-qs.noarch.0.0.6.6-3.el7 将被 安装
---> 软件包 nodejs-through.noarch.0.2.3.4-2.el7 将被 安装
---> 软件包 nodejs-tunnel-agent.noarch.0.0.3.0-1.el7 将被 安装
---> 软件包 nodejs-wordwrap.noarch.0.0.0.2-4.el7 将被 安装
---> 软件包 npm.x86_64.1.3.10.10-1.6.11.1.1.el7 将被 安装
--> 正在检查事务
---> 软件包 nodejs-asn1.noarch.0.0.1.11-3.el7 将被 安装
---> 软件包 nodejs-assert-plus.noarch.0.0.1.4-1.el7 将被 安装
---> 软件包 nodejs-boom.noarch.0.0.4.2-2.el7 将被 安装
---> 软件包 nodejs-combined-stream.noarch.0.0.0.4-3.el7 将被 安装
--> 正在处理依赖关系 npm(delayed-stream) = 0.0.5,它被软件包 nodejs-combined-stream-0.0.4-3.el7.noarch 需要
---> 软件包 nodejs-cryptiles.noarch.0.0.2.2-1.el7 将被 安装
---> 软件包 nodejs-ctype.noarch.0.0.5.3-3.el7 将被 安装
---> 软件包 nodejs-hoek.noarch.0.0.9.1-1.el7 将被 安装
---> 软件包 nodejs-sntp.noarch.0.0.2.4-1.el7 将被 安装
--> 正在检查事务
---> 软件包 nodejs-delayed-stream.noarch.0.0.0.5-5.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

===============================================================================================================================================================================================
 Package                                                 架构                                版本                                                   源                                    大小
===============================================================================================================================================================================================
正在安装:
 elasticdump                                             noarch                              2.2.0-2.el7                                            epel                                  26 k
为依赖而安装:
 http-parser                                             x86_64                              2.7.1-5.el7_4                                          updates                               28 k
 libuv                                                   x86_64                              1:1.10.2-1.el7                                         epel                                 109 k
 nodejs                                                  x86_64                              1:6.11.1-1.el7                                         epel                                 4.5 M
 nodejs-asn1                                             noarch                              0.1.11-3.el7                                           epel                                  11 k
 nodejs-assert-plus                                      noarch                              0.1.4-1.el7                                            epel                                 7.3 k
 nodejs-async                                            noarch                              0.2.10-1.el7                                           epel                                  21 k
 nodejs-aws-sign                                         noarch                              0.3.0-1.el7                                            epel                                 5.7 k
 nodejs-boom                                             noarch                              0.4.2-2.el7                                            epel                                  37 k
 nodejs-combined-stream                                  noarch                              0.0.4-3.el7                                            epel                                 7.9 k
 nodejs-cookie-jar                                       noarch                              1:0.3.0-1.el7                                          epel                                 6.1 k
 nodejs-cryptiles                                        noarch                              0.2.2-1.el7                                            epel                                 6.9 k
 nodejs-ctype                                            noarch                              0.5.3-3.el7                                            epel                                  31 k
 nodejs-delayed-stream                                   noarch                              0.0.5-5.el7                                            epel                                 7.9 k
 nodejs-forever-agent                                    noarch                              0.5.0-1.el7                                            epel                                 5.6 k
 nodejs-form-data                                        noarch                              0.1.1-1.el7                                            epel                                  11 k
 nodejs-hawk                                             noarch                              1.0.0-1.el7                                            epel                                 105 k
 nodejs-hoek                                             noarch                              0.9.1-1.el7                                            epel                                  51 k
 nodejs-http-signature                                   noarch                              0.10.0-3.el7                                           epel                                  17 k
 nodejs-json-stringify-safe                              noarch                              5.0.0-1.el7                                            epel                                 6.6 k
 nodejs-jsonparse                                        noarch                              1.0.0-2.el7                                            epel                                  10 k
 nodejs-jsonstream                                       noarch                              0.10.0-2.el7                                           epel                                 9.5 k
 nodejs-mime                                             noarch                              1.2.11-1.el7                                           epel                                  22 k
 nodejs-node-uuid                                        noarch                              1.4.1-1.el7                                            epel                                  10 k
 nodejs-oauth-sign                                       noarch                              0.3.0-1.el7                                            epel                                 4.9 k
 nodejs-optimist                                         noarch                              0.4.0-1.el7                                            epel                                  15 k
 nodejs-qs                                               noarch                              0.6.6-3.el7                                            epel                                 8.7 k
 nodejs-request                                          noarch                              2.25.0-1.el7                                           epel                                  27 k
 nodejs-sntp                                             noarch                              0.2.4-1.el7                                            epel                                  10 k
 nodejs-through                                          noarch                              2.3.4-2.el7                                            epel                                 7.1 k
 nodejs-tunnel-agent                                     noarch                              0.3.0-1.el7                                            epel                                 6.3 k
 nodejs-wordwrap                                         noarch                              0.0.2-4.el7                                            epel                                 6.4 k
 npm                                                     x86_64                              1:3.10.10-1.6.11.1.1.el7                               epel                                 2.5 M

事务概要
===============================================================================================================================================================================================
安装  1 软件包 (+32 依赖软件包)

总下载量:7.7 M
安装大小:26 M
Is this ok [y/d/N]: y
Downloading packages:
(1/33): http-parser-2.7.1-5.el7_4.x86_64.rpm                                                                                                                            |  28 kB  00:00:00     
(2/33): elasticdump-2.2.0-2.el7.noarch.rpm                                                                                                                              |  26 kB  00:00:00     
(3/33): libuv-1.10.2-1.el7.x86_64.rpm                                                                                                                                   | 109 kB  00:00:00     
(4/33): nodejs-6.11.1-1.el7.x86_64.rpm                                                                                                                                  | 4.5 MB  00:00:00     
(5/33): nodejs-asn1-0.1.11-3.el7.noarch.rpm                                                                                                                             |  11 kB  00:00:00     
(6/33): nodejs-assert-plus-0.1.4-1.el7.noarch.rpm                                                                                                                       | 7.3 kB  00:00:00     
(7/33): nodejs-async-0.2.10-1.el7.noarch.rpm                                                                                                                            |  21 kB  00:00:00     
(8/33): nodejs-aws-sign-0.3.0-1.el7.noarch.rpm                                                                                                                          | 5.7 kB  00:00:00     
(9/33): nodejs-boom-0.4.2-2.el7.noarch.rpm                                                                                                                              |  37 kB  00:00:00     
(10/33): nodejs-combined-stream-0.0.4-3.el7.noarch.rpm                                                                                                                  | 7.9 kB  00:00:00     
(11/33): nodejs-cookie-jar-0.3.0-1.el7.noarch.rpm                                                                                                                       | 6.1 kB  00:00:00     
(12/33): nodejs-cryptiles-0.2.2-1.el7.noarch.rpm                                                                                                                        | 6.9 kB  00:00:00     
(13/33): nodejs-ctype-0.5.3-3.el7.noarch.rpm                                                                                                                            |  31 kB  00:00:00     
(14/33): nodejs-delayed-stream-0.0.5-5.el7.noarch.rpm                                                                                                                   | 7.9 kB  00:00:00     
(15/33): nodejs-forever-agent-0.5.0-1.el7.noarch.rpm                                                                                                                    | 5.6 kB  00:00:00     
(16/33): nodejs-form-data-0.1.1-1.el7.noarch.rpm                                                                                                                        |  11 kB  00:00:00     
(17/33): nodejs-hawk-1.0.0-1.el7.noarch.rpm                                                                                                                             | 105 kB  00:00:00     
(18/33): nodejs-hoek-0.9.1-1.el7.noarch.rpm                                                                                                                             |  51 kB  00:00:00     
(19/33): nodejs-http-signature-0.10.0-3.el7.noarch.rpm                                                                                                                  |  17 kB  00:00:00     
(20/33): nodejs-json-stringify-safe-5.0.0-1.el7.noarch.rpm                                                                                                              | 6.6 kB  00:00:00     
(21/33): nodejs-jsonparse-1.0.0-2.el7.noarch.rpm                                                                                                                        |  10 kB  00:00:00     
(22/33): nodejs-jsonstream-0.10.0-2.el7.noarch.rpm                                                                                                                      | 9.5 kB  00:00:00     
(23/33): nodejs-mime-1.2.11-1.el7.noarch.rpm                                                                                                                            |  22 kB  00:00:00     
(24/33): nodejs-node-uuid-1.4.1-1.el7.noarch.rpm                                                                                                                        |  10 kB  00:00:00     
(25/33): nodejs-oauth-sign-0.3.0-1.el7.noarch.rpm                                                                                                                       | 4.9 kB  00:00:00     
(26/33): nodejs-optimist-0.4.0-1.el7.noarch.rpm                                                                                                                         |  15 kB  00:00:00     
(27/33): nodejs-qs-0.6.6-3.el7.noarch.rpm                                                                                                                               | 8.7 kB  00:00:00     
(28/33): nodejs-request-2.25.0-1.el7.noarch.rpm                                                                                                                         |  27 kB  00:00:00     
(29/33): nodejs-sntp-0.2.4-1.el7.noarch.rpm                                                                                                                             |  10 kB  00:00:00     
(30/33): nodejs-through-2.3.4-2.el7.noarch.rpm                                                                                                                          | 7.1 kB  00:00:00     
(31/33): nodejs-tunnel-agent-0.3.0-1.el7.noarch.rpm                                                                                                                     | 6.3 kB  00:00:00     
(32/33): nodejs-wordwrap-0.0.2-4.el7.noarch.rpm                                                                                                                         | 6.4 kB  00:00:00     
(33/33): npm-3.10.10-1.6.11.1.1.el7.x86_64.rpm                                                                                                                          | 2.5 MB  00:00:00     
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
总计                                                                                                                                                           2.0 MB/s | 7.7 MB  00:00:03     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
警告:RPM 数据库已被非 yum 程序修改。
** 发现 1 个已存在的 RPM 数据库问题, 'yum check' 输出如下:
rhn-check-2.0.2-6.el7.noarch 有缺少的需求 yum-rhn-plugin >= ('0', '1.6.4', '1')
  正在安装    : 1:libuv-1.10.2-1.el7.x86_64                                                                                                                                               1/33 
  正在安装    : http-parser-2.7.1-5.el7_4.x86_64                                                                                                                                          2/33 
  正在安装    : 1:npm-3.10.10-1.6.11.1.1.el7.x86_64                                                                                                                                       3/33 
  正在安装    : 1:nodejs-6.11.1-1.el7.x86_64                                                                                                                                              4/33 
  正在安装    : nodejs-hoek-0.9.1-1.el7.noarch                                                                                                                                            5/33 
  正在安装    : nodejs-boom-0.4.2-2.el7.noarch                                                                                                                                            6/33 
  正在安装    : nodejs-mime-1.2.11-1.el7.noarch                                                                                                                                           7/33 
  正在安装    : nodejs-async-0.2.10-1.el7.noarch                                                                                                                                          8/33 
  正在安装    : nodejs-cryptiles-0.2.2-1.el7.noarch                                                                                                                                       9/33 
  正在安装    : nodejs-sntp-0.2.4-1.el7.noarch                                                                                                                                           10/33 
  正在安装    : nodejs-hawk-1.0.0-1.el7.noarch                                                                                                                                           11/33 
  正在安装    : nodejs-forever-agent-0.5.0-1.el7.noarch                                                                                                                                  12/33 
  正在安装    : nodejs-aws-sign-0.3.0-1.el7.noarch                                                                                                                                       13/33 
  正在安装    : nodejs-qs-0.6.6-3.el7.noarch                                                                                                                                             14/33 
  正在安装    : nodejs-wordwrap-0.0.2-4.el7.noarch                                                                                                                                       15/33 
  正在安装    : nodejs-optimist-0.4.0-1.el7.noarch                                                                                                                                       16/33 
  正在安装    : nodejs-assert-plus-0.1.4-1.el7.noarch                                                                                                                                    17/33 
  正在安装    : nodejs-oauth-sign-0.3.0-1.el7.noarch                                                                                                                                     18/33 
  正在安装    : nodejs-tunnel-agent-0.3.0-1.el7.noarch                                                                                                                                   19/33 
  正在安装    : nodejs-asn1-0.1.11-3.el7.noarch                                                                                                                                          20/33 
  正在安装    : nodejs-delayed-stream-0.0.5-5.el7.noarch                                                                                                                                 21/33 
  正在安装    : nodejs-combined-stream-0.0.4-3.el7.noarch                                                                                                                                22/33 
  正在安装    : nodejs-form-data-0.1.1-1.el7.noarch                                                                                                                                      23/33 
  正在安装    : 1:nodejs-cookie-jar-0.3.0-1.el7.noarch                                                                                                                                   24/33 
  正在安装    : nodejs-jsonparse-1.0.0-2.el7.noarch                                                                                                                                      25/33 
  正在安装    : nodejs-through-2.3.4-2.el7.noarch                                                                                                                                        26/33 
  正在安装    : nodejs-jsonstream-0.10.0-2.el7.noarch                                                                                                                                    27/33 
  正在安装    : nodejs-node-uuid-1.4.1-1.el7.noarch                                                                                                                                      28/33 
  正在安装    : nodejs-ctype-0.5.3-3.el7.noarch                                                                                                                                          29/33 
  正在安装    : nodejs-http-signature-0.10.0-3.el7.noarch                                                                                                                                30/33 
  正在安装    : nodejs-json-stringify-safe-5.0.0-1.el7.noarch                                                                                                                            31/33 
  正在安装    : nodejs-request-2.25.0-1.el7.noarch                                                                                                                                       32/33 
  正在安装    : elasticdump-2.2.0-2.el7.noarch                                                                                                                                           33/33 
  验证中      : elasticdump-2.2.0-2.el7.noarch                                                                                                                                            1/33 
  验证中      : nodejs-forever-agent-0.5.0-1.el7.noarch                                                                                                                                   2/33 
  验证中      : nodejs-aws-sign-0.3.0-1.el7.noarch                                                                                                                                        3/33 
  验证中      : nodejs-qs-0.6.6-3.el7.noarch                                                                                                                                              4/33 
  验证中      : http-parser-2.7.1-5.el7_4.x86_64                                                                                                                                          5/33 
  验证中      : nodejs-combined-stream-0.0.4-3.el7.noarch                                                                                                                                 6/33 
  验证中      : nodejs-wordwrap-0.0.2-4.el7.noarch                                                                                                                                        7/33 
  验证中      : nodejs-assert-plus-0.1.4-1.el7.noarch                                                                                                                                     8/33 
  验证中      : nodejs-oauth-sign-0.3.0-1.el7.noarch                                                                                                                                      9/33 
  验证中      : nodejs-hoek-0.9.1-1.el7.noarch                                                                                                                                           10/33 
  验证中      : nodejs-cryptiles-0.2.2-1.el7.noarch                                                                                                                                      11/33 
  验证中      : nodejs-jsonstream-0.10.0-2.el7.noarch                                                                                                                                    12/33 
  验证中      : nodejs-request-2.25.0-1.el7.noarch                                                                                                                                       13/33 
  验证中      : nodejs-http-signature-0.10.0-3.el7.noarch                                                                                                                                14/33 
  验证中      : 1:libuv-1.10.2-1.el7.x86_64                                                                                                                                              15/33 
  验证中      : nodejs-tunnel-agent-0.3.0-1.el7.noarch                                                                                                                                   16/33 
  验证中      : nodejs-mime-1.2.11-1.el7.noarch                                                                                                                                          17/33 
  验证中      : nodejs-hawk-1.0.0-1.el7.noarch                                                                                                                                           18/33 
  验证中      : nodejs-asn1-0.1.11-3.el7.noarch                                                                                                                                          19/33 
  验证中      : nodejs-delayed-stream-0.0.5-5.el7.noarch                                                                                                                                 20/33 
  验证中      : 1:npm-3.10.10-1.6.11.1.1.el7.x86_64                                                                                                                                      21/33 
  验证中      : nodejs-optimist-0.4.0-1.el7.noarch                                                                                                                                       22/33 
  验证中      : nodejs-sntp-0.2.4-1.el7.noarch                                                                                                                                           23/33 
  验证中      : nodejs-form-data-0.1.1-1.el7.noarch                                                                                                                                      24/33 
  验证中      : 1:nodejs-cookie-jar-0.3.0-1.el7.noarch                                                                                                                                   25/33 
  验证中      : nodejs-boom-0.4.2-2.el7.noarch                                                                                                                                           26/33 
  验证中      : 1:nodejs-6.11.1-1.el7.x86_64                                                                                                                                             27/33 
  验证中      : nodejs-jsonparse-1.0.0-2.el7.noarch                                                                                                                                      28/33 
  验证中      : nodejs-through-2.3.4-2.el7.noarch                                                                                                                                        29/33 
  验证中      : nodejs-node-uuid-1.4.1-1.el7.noarch                                                                                                                                      30/33 
  验证中      : nodejs-ctype-0.5.3-3.el7.noarch                                                                                                                                          31/33 
  验证中      : nodejs-async-0.2.10-1.el7.noarch                                                                                                                                         32/33 
  验证中      : nodejs-json-stringify-safe-5.0.0-1.el7.noarch                                                                                                                            33/33 

已安装:
  elasticdump.noarch 0:2.2.0-2.el7                                                                                                                                                             

作为依赖被安装:
  http-parser.x86_64 0:2.7.1-5.el7_4             libuv.x86_64 1:1.10.2-1.el7                    nodejs.x86_64 1:6.11.1-1.el7                       nodejs-asn1.noarch 0:0.1.11-3.el7        
  nodejs-assert-plus.noarch 0:0.1.4-1.el7        nodejs-async.noarch 0:0.2.10-1.el7             nodejs-aws-sign.noarch 0:0.3.0-1.el7               nodejs-boom.noarch 0:0.4.2-2.el7         
  nodejs-combined-stream.noarch 0:0.0.4-3.el7    nodejs-cookie-jar.noarch 1:0.3.0-1.el7         nodejs-cryptiles.noarch 0:0.2.2-1.el7              nodejs-ctype.noarch 0:0.5.3-3.el7        
  nodejs-delayed-stream.noarch 0:0.0.5-5.el7     nodejs-forever-agent.noarch 0:0.5.0-1.el7      nodejs-form-data.noarch 0:0.1.1-1.el7              nodejs-hawk.noarch 0:1.0.0-1.el7         
  nodejs-hoek.noarch 0:0.9.1-1.el7               nodejs-http-signature.noarch 0:0.10.0-3.el7    nodejs-json-stringify-safe.noarch 0:5.0.0-1.el7    nodejs-jsonparse.noarch 0:1.0.0-2.el7    
  nodejs-jsonstream.noarch 0:0.10.0-2.el7        nodejs-mime.noarch 0:1.2.11-1.el7              nodejs-node-uuid.noarch 0:1.4.1-1.el7              nodejs-oauth-sign.noarch 0:0.3.0-1.el7   
  nodejs-optimist.noarch 0:0.4.0-1.el7           nodejs-qs.noarch 0:0.6.6-3.el7                 nodejs-request.noarch 0:2.25.0-1.el7               nodejs-sntp.noarch 0:0.2.4-1.el7         
  nodejs-through.noarch 0:2.3.4-2.el7            nodejs-tunnel-agent.noarch 0:0.3.0-1.el7       nodejs-wordwrap.noarch 0:0.0.2-4.el7               npm.x86_64 1:3.10.10-1.6.11.1.1.el7      

完毕!
[root@localhost ~]#

elasticdump相关功能描述:

[root@localhost ~]# elasticdump --help
elasticdump: Import and export tools for elasticsearch
version: 2.2.0

Usage: elasticdump --input SOURCE --output DESTINATION [OPTIONS]

--input
                    Source location (required)
--input-index
                    Source index and type
                    (default: all, example: index/type)
--output
                    Destination location (required)
--output-index
                    Destination index and type
                    (default: all, example: index/type)
--limit
                    How many objects to move in batch per operation
                    limit is approximate for file streams
                    (default: 100)
--debug
                    Display the elasticsearch commands being used
                    (default: false)
--type
                    What are we exporting?
                    (default: data, options: [data, mapping])
--delete
                    Delete documents one-by-one from the input as they are
                    moved.  Will not delete the source index
                    (default: false)
--searchBody
                    Preform a partial extract based on search results
                    (when ES is the input,
                    (default: '{"query": { "match_all": {} } }'))
--sourceOnly
                    Output only the json contained within the document _source
                    Normal: {"_index":"","_type":"","_id":"", "_source":{SOURCE}}
                    sourceOnly: {SOURCE}
                    (default: false)
--all
                    Load/store documents from ALL indexes
                    (default: false)
--ignore-errors
                    Will continue the read/write loop on write error
                    (default: false)
--scrollTime
                    Time the nodes will hold the requested search in order.
                    (default: 10m)
--maxSockets
                    How many simultaneous HTTP requests can we process make?
                    (default:
                      5 [node <= v0.10.x] /
                      Infinity [node >= v0.11.x] )
--timeout
                    Integer containing the number of milliseconds to wait for
                    a request to respond before aborting the request. Passed
                    directly to the request library. Mostly used when you don't
                    care too much if you lose some data when importing
                    but rather have speed.
--offset
                    Integer containing the number of rows you wish to skip
                    ahead from the input transport.  When importing a large
                    index, things can go wrong, be it connectivity, crashes,
                    someone forgetting to `screen`, etc.  This allows you
                    to start the dump again from the last known line written
                    (as logged by the `offset` in the output).  Please be
                    advised that since no sorting is specified when the
                    dump is initially created, there's no real way to
                    guarantee that the skipped rows have already been
                    written/parsed.  This is more of an option for when
                    you want to get most data as possible in the index
                    without concern for losing some rows in the process,
                    similar to the `timeout` option.
--inputTransport
                    Provide a custom js file to us as the input transport
--outputTransport
                    Provide a custom js file to us as the output transport
--toLog
                    When using a custom outputTransport, should log lines
                    be appended to the output stream?
                    (default: true, except for `$`)
--help
                    This page

Examples:

# Copy an index from production to staging with mappings:
elasticdump 
  --input=http://production.es.com:9200/my_index 
  --output=http://staging.es.com:9200/my_index 
  --type=mapping
elasticdump 
  --input=http://production.es.com:9200/my_index 
  --output=http://staging.es.com:9200/my_index 
  --type=data

# Backup index data to a file:
elasticdump 
  --input=http://production.es.com:9200/my_index 
  --output=/data/my_index_mapping.json 
  --type=mapping
elasticdump 
  --input=http://production.es.com:9200/my_index 
  --output=/data/my_index.json 
  --type=data

# Backup and index to a gzip using stdout:
elasticdump 
  --input=http://production.es.com:9200/my_index 
  --output=$ 
  | gzip > /data/my_index.json.gz

# Backup the results of a query to a file
elasticdump 
  --input=http://production.es.com:9200/my_index 
  --output=query.json 
  --searchBody '{"query":{"term":{"username": "admin"}}}'

------------------------------------------------------------------------------
Learn more @ https://github.com/taskrabbit/elasticsearch-dump

[root@localhost ~]# 

重点说明:
依据上述的帮助文件,我们重点看elasticdump --input SOURCE --output DESTINATION
这里的source和destination可以是es的数据源,也可以是文件。也就是说,这个命令elasticdump既可以完成数据的导出,也可以完成数据的导入。
当表示es的数据源时,必须是{protocol}://{host}:{port}/{index}.

1. 将es集群中的某个index的数据导出到文件中

[root@localhost ~]# elasticdump --input http://10.90.7.10:9200/robotkdb --output /opt/shihuc/robotkdb.json
Thu, 21 Sep 2017 07:04:37 GMT | starting dump
Thu, 21 Sep 2017 07:04:37 GMT | got 100 objects from source elasticsearch (offset: 0)
Thu, 21 Sep 2017 07:04:37 GMT | sent 100 objects to destination file, wrote 100
Thu, 21 Sep 2017 07:04:37 GMT | got 100 objects from source elasticsearch (offset: 100)
Thu, 21 Sep 2017 07:04:37 GMT | sent 100 objects to destination file, wrote 100
Thu, 21 Sep 2017 07:04:37 GMT | got 8 objects from source elasticsearch (offset: 200)
Thu, 21 Sep 2017 07:04:37 GMT | sent 8 objects to destination file, wrote 8
Thu, 21 Sep 2017 07:04:37 GMT | got 0 objects from source elasticsearch (offset: 208)
Thu, 21 Sep 2017 07:04:37 GMT | Total Writes: 208
Thu, 21 Sep 2017 07:04:37 GMT | dump complete
[root@localhost ~]# 

2.直接删除指定的type下的内容

[root@localhost ~]# curl -XDELETE "http://10.90.7.10:9200/robotkdb/weibao?v"
No handler found for uri [/robotkdb/weibao?v] and method [DELETE][root@localhost ~]#

删除不成功。
查询资料显示说,ES2.x版本以上的系统中,禁止了直接删除type

那我要快速删除一个type的内容,该如何处理呢?其实是有的,安装delete-by-query的插件进行。安装完成后,将Elasticsearch重启一下

[root@localhost bin]# ll
总用量 324
-rwxr-xr-x 1 es es   5551 8月  23 2016 elasticsearch
-rw-rw-r-- 1 es es    909 8月  23 2016 elasticsearch.bat
-rw-rw-r-- 1 es es   3351 9月  23 2016 elasticsearch.in.bat
-rwxr-xr-x 1 es es   2814 8月  23 2016 elasticsearch.in.sh
-rw-rw-r-- 1 es es 104448 7月  26 2016 elasticsearch-service-mgr.exe
-rw-rw-r-- 1 es es 103936 7月  26 2016 elasticsearch-service-x64.exe
-rw-rw-r-- 1 es es  80896 7月  26 2016 elasticsearch-service-x86.exe
-rwxr-xr-x 1 es es   2992 8月  23 2016 plugin
-rw-rw-r-- 1 es es   1303 8月  23 2016 plugin.bat
-rw-rw-r-- 1 es es   6872 8月  23 2016 service.bat
[root@localhost bin]# ./plugin install delete-by-query                 #注意,要到elasticsearch的安装路径下的bin下面执行这个命令
-> Installing delete-by-query...
Trying https://download.elastic.co/elasticsearch/release/org/elasticsearch/plugin/delete-by-query/2.4.1/delete-by-query-2.4.1.zip ...
Downloading ..DONE
Verifying https://download.elastic.co/elasticsearch/release/org/elasticsearch/plugin/delete-by-query/2.4.1/delete-by-query-2.4.1.zip checksums if available ...
Downloading .DONE
Installed delete-by-query into /opt/ES/elasticsearch-2.4.1/plugins/delete-by-query
[root@localhost bin]# 

重启elasticsearch的过程,就不描述了。然后再用命令执行删除指定的type的数据:

[root@localhost ES]# curl -XDELETE "http://10.90.7.10:9200/robotkdb/weibao/_query?pretty" -d '{
"query":{
"match_all":{}
}}'
{
  "took" : 0,
  "timed_out" : false,
  "_indices" : {
    "_all" : {
      "found" : 208,
      "deleted" : 208,
      "missing" : 0,
      "failed" : 0
    },
    "robotkdb" : {
      "found" : 208,
      "deleted" : 208,
      "missing" : 0,
      "failed" : 0
    }
  },
  "failures" : [ ]
}
[root@localhost ES]#

从上述结果看,没有错误。那么,再去查看下,weibao这个type下,还有没有数据!

[root@localhost ES]# curl -XGET "http://10.90.7.10:9200/robotkdb/weibao/_search?pretty"
{
  "took" : 3,
  "timed_out" : false,
  "_shards" : {
    "total" : 5,
    "successful" : 5,
    "failed" : 0
  },
  "hits" : {
    "total" : 0,
    "max_score" : null,
    "hits" : [ ]
  }
}

说明删除指定type的内容成功了。

3. elasticdump数据恢复

那最后再来恢复下刚才删除掉的208个记录吧。前面不是备份了一个数据吗,在这个文件里面/opt/shihuc/robotkdb.json

[root@localhost shihuc]# elasticdump --input /opt/shihuc/robotkdb.json --output "http://10.90.7.10:9200/robotkdb"
Thu, 21 Sep 2017 07:16:03 GMT | starting dump
Thu, 21 Sep 2017 07:16:03 GMT | got 100 objects from source file (offset: 0)
Thu, 21 Sep 2017 07:16:04 GMT | sent 100 objects to destination elasticsearch, wrote 100
Thu, 21 Sep 2017 07:16:04 GMT | got 108 objects from source file (offset: 100)
Thu, 21 Sep 2017 07:16:04 GMT | sent 108 objects to destination elasticsearch, wrote 108
Thu, 21 Sep 2017 07:16:04 GMT | got 0 objects from source file (offset: 208)
Thu, 21 Sep 2017 07:16:04 GMT | Total Writes: 208
Thu, 21 Sep 2017 07:16:04 GMT | dump complete

最后在浏览器上访问看看吧,验证数据载入、恢复是否成功!

Elasticsearch的数据备份,删除以及恢复逻辑,到此验证完毕!

总结:

1. Elasticsearch的2.x以上版本不支持直接删除type级别的数据。支持删除index,也支持逐个id的删除。

2. Elasticsearch的数据备份和恢复,没有直接的指令操作,需要安装插件elasticdump来实现。

原文地址:https://www.cnblogs.com/shihuc/p/7570214.html