一、安装支撑组件
yum install nodejs
yum install npm
npm install elasticdump -g
二、修改es的批处理数据量级
因为默认批查询返回数据上限是10000,想要一次查更多需要改索引参数
curl -XPUT "http://127.0.0.1:9200/index_name/_settings" -H 'Content-Type: application/json' -d'
{
"index" : {
"max_result_window" : 100000
}
}'
三、批量迁移
#从源es迁移到文件,match参数正则匹配索引名,limit是批量数据个数,includeType包含
#data,mapping,analyzer,alias,settings,template
multielasticdump \
--direction=dump \
--match='^.*$' \
--input=http://x.x.x.x:9200 \
--includeType='data,mapping' \
--limit=2000 \
--output=/tmp/es_backup
#从文件迁移到目的es
multielasticdump \
--direction=load \
--match='^.*$' \
--input=/tmp/es_backup \
--includeType='data,mapping' \
--limit=2000 \
--output=http://s.s.s.s:9200
四、单个索引迁移
# Copy an index from production to staging with analyzer and mapping:
elasticdump \
--input=http://production.es.com:9200/my_index \
--output=http://staging.es.com:9200/my_index \
--type=analyzer
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\"}}}"
# Copy a single shard data:
elasticdump \
--input=http://es.com:9200/api \
--output=http://es.com:9200/api2 \
--params='{"preference" : "_shards:0"}'
# Backup aliases to a file
elasticdump \
--input=http://es.com:9200/index-name/alias-filter \
--output=alias.json \
--type=alias
# Import aliases into ES
elasticdump \
--input=./alias.json \
--output=http://es.com:9200 \
--type=alias
# Backup templates to a file
elasticdump \
--input=http://es.com:9200/template-filter \
--output=templates.json \
--type=template
# Import templates into ES
elasticdump \
--input=./templates.json \
--output=http://es.com:9200 \
--type=template
#遍历同步集合中的索引
#!/bin/bash
# 定义包含文件路径的数组
indexes=("index1" "index2" "index3")
# 遍历数组中的每个元素
for file in "${indexes[@]}"
do
elasticdump \
--input=http://10.0.0.61:9200/$file \
--output=http://127.0.0.1:9200/$file \
--type=data \
--limit=9999
echo "已同步索引: $file"
done
#后台执行
nohup sh es_dump.sh > dump.log 2>&1 &