First Python script

Source: Internet
Author: User

#脚本用于创建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])

First Python script

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.