es数据迁移(原创)

#!/usr/bin/python3
import urllib.request
import requests
import subprocess

url = 'http://x.x.x.x:9200/_cat/indices?'
def s_index(url):
r = requests.get(url)
r = r.text
r = r.split("\n")
indexS = []
for row in r[:-1]:
# print(row)
row = row.split(" ")
row_l = []
for row_smarl in row:
if row_smarl != "":
row_l.append(row_smarl)

indexS.append(row_l[2])
#print(indexS)
return indexS
# print(row_l[2])

# print(row)


def mig_start(indices):
host = "XX.XX.XX.XX"
port = "9200"
dest = "http://XX.XX.XX.XX:9200"
print("索引列表是:",indices)
for _index in indices:
print ("Start migration %s" % (_index))
print("开始reindex")
data_dump = subprocess.Popen(''' curl -POST -H "Content-Type: application/json" -s "%s/_reindex" -d '
{
"source": {
"remote": {
"host": "http://%s:9200"
},
"index": "%s",
"query": {
"match_all": {}
}
},
"dest": {
"index": "%s"
}
}
}' ''' % (dest, host, _index, _index), shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
#break
print(data_dump.stdout.read())
print("host:%s--reindex完成" % host)

mig_start(s_index(url))

 

posted @ 2020-08-10 18:05  木易-故事里的人  阅读(1457)  评论(0编辑  收藏  举报