文章目錄
- 0.安裝數據遷移工具
- 1.導出數據
- 2.導出mapping
- 3.導出查詢模板
- 4.拷貝插件
- 5.拷貝配置
- 6.導入到目標電腦上
0.安裝數據遷移工具
Elasticsearch dump是一個用于將Elasticsearch索引數據導出為JSON格式的工具。你可以使用Elasticsearch dump通過命令行或編程接口來導出數據。以下是一個簡單的示例,假設你已經安裝了Node.js和npm:
使用npm安裝elasticsearch-dump:
npm install elasticdump@6.110.0 -g
1.導出數據
elasticdump --input=http://source-elasticsearch-host:9200/your_index --output=/path/to/your/index_data.json --type=data
2.導出mapping
elasticdump --input=http://source-elasticsearch-host:9200/your_index --output=/path/to/your/index_mapping.json --type=mapping
3.導出查詢模板
使用以下命令從源Elasticsearch實例中挨個獲取查詢模板,并將返回的JSON數據保存到一個文件中:
curl -XGET 'http://your-elasticsearch-host:9200/_scripts/查詢模板的id' > 文件名.json
4.拷貝插件
插件存放在安裝目錄下的plugins文件夾中。一個插件對應一個子文件夾。
5.拷貝配置
拷貝原來的elasticsearch.yml配置。
6.導入到目標電腦上
- 安裝Elasticsearch:
在目標電腦上安裝同版本的Elasticsearch。安裝教程
- 安裝elasticdump工具:
npm install elasticdump@6.110.0 -g
- 導入插件:
將源電腦導出的插件放置到目標電腦的es的安裝目錄的plugins文件夾下。
重啟es服務。
通過以下命令可以查看插件是否生效:
GET http://your_ip:9200/_cat/plugins
- 導入mapping:
elasticdump --input=/path/to/your/index_mapping.json --output=http://target-elasticsearch-host:9200/your_index --type=mapping
- 導入data:
elasticdump --input=/path/to/your/output/file.json --output=http://target-elasticsearch-host:9200/your_index --type=data
- 導入查詢模板:
針對每一個查詢模板json文件,進行以下操作來創建查詢模板:
POST _scripts/查詢模板id
{"script": ...這里應該是JSON文件中對應的script鍵的值的部分...
}
到這里基本就可以了,當然如果你的Elasticsearch里面包含了其他例如索引模板這樣的東西,還需要另外遷移過去。