elasticdump可以直接下載es中得數據,需要通過npm方式安裝下載elasticdump,所以需要先安裝nodejs
1. 安裝nodejs
將該文件上傳到服務器中,或直接使用wget方式下載nodejs;切換到你得下載目錄中,然后進行解壓:
[root@localhost ~]# tar -xvf node-v10.16.0-linux-x64.tar.xz
使用命令解壓文件后,然后mv到想要的目錄中去,不用進行安裝,將node下的bin目錄配置到/etc/profile中即可,在/etc/profile中最后一行添加
export PATH=$PATH:xxx_node_home_dir/bin
然后source /etc/profile
即可,輸入命令進行查看node和npm是否安裝成功
node -v
npm -v
這種方式是在/etc/profile配置目錄方式,從而可以使用node或npm方式,也可以使用軟連接,如下所示,效果也差不多(在我這里測試的時候,如果使用軟鏈接方式,全局安裝elasticdump后會出現找不到命令的情況,而使用HOME目錄方式就不會存在該問題,推薦HOME目錄配置方式)
[root@localhost ~]# ln -s ~/node-v10.16.0-linux-x64/bin/node /usr/bin/node [root@localhost ~]# ln -s ~/node-v10.16.0-linux-x64/bin/npm /usr/bin/npm
2. 下載ealsticdump
[root@localhost ~]# npm install elasticdump -g
這種方式安裝后,可以全局使用,如果在其他目錄中,使用下面命令,如果提示沒有安裝xxx命令的話, 那就使npm本地安裝模式,npm install elasticdump 安裝完成后,切換到本地`node_modules/elasticdump/` 目錄下,通過bin/elasticdump同樣可以使用命令
[root@localhost ~]# elasticdump
3. 下載數據示例
bin/elasticdump --input=http://127.0.0.1:9200/test_index \ --output=./test_index.json --type=data --sourceOnly=true \ --fileSize=512mb --retryAttempts=3 \ --searchBody='{"query":{"bool":{"must":[{"range":{"@timestamp":{"gte":"2021-06-01","lt":"2021-07-01"}}},{"term":{"project.keyword":{"value":"xxxx"}}}]}}}'
示例說明:
--type可以不要,默認就是data,可以設置為mapping和其他,表示要下載的數據
--sourceOnly,默認值為false,正常的數據中,是包含一些_id, _score,_source,_index等信息,如果設置為true,只會把_source中的數據下載回來;
--fileSize設置文件滾動大小
--retryAttempt設置失敗重試次數
--searchBody設置你的查詢條件
上面示例中,除了--input和--output以外,其他都可以不進行設置,示例的下載過程如下
elasticdump還有很多的參數可以設置,其可以導出,也可以導入,更多信息通過命令進行查看
bin/elasticdump --help