#脚本用于创建es索引及别名
#!/usr/bin/python
import json
import requests
import datetime
import time
#get tomorrow date
now = datetime.datetime.now()
delta = datetime.timedelta(days=1)
n_days = now + delta
tomorrowDate2 = int(n_days.strftime(‘%M‘))//10
str = ‘%d‘%tomorrowDate2
tomorrowDate = n_days.strftime(‘%Y-%m-%d-%H‘)+"-"+str
#create_indices_function
def create_index(type):
index_name = type+"-njyh-"+tomorrowDate
req = "http://ip:9600/" + index_name + "/"
stats = requests.put(req).json()
time.sleep(1)
return
#create_alias_function_function
def create_alias(type,alias_name):
index_name = type+"-njyh-"+tomorrowDate
req="http://ip:9600/"+index_name+"/_alias/"+alias_name+"-"+tom0rrowDate
requests.put(req)
time.sleep(1)
return
list1 = [‘index_name1‘,‘index_name2‘]
for index in range(len(list1)):
create_index(list1[index])
create_alias(list1[index],list1[index])
原文地址:https://www.cnblogs.com/zhang-zhao/p/9226208.html