elasticsearch_clean.py
720 Bytes
#!/usr/bin/python
# coding: utf-8
import urllib
import urllib2
import datetime
import time
import sys
if __name__ == '__main__':
param_day = 7
if(len(sys.argv) >= 2) :
param_day=int(sys.argv[1])
# http://localhost:9200/_cat/indices?v
date_now = datetime.date.today()
days_before_30 = date_now - datetime.timedelta(days=param_day)
date_format = days_before_30.__format__('%Y.%m.%d')
url_delete = "http://127.0.0.1:9200/*-{}".format(date_format)
request_delete = urllib2.Request(url_delete)
request_delete.get_method = lambda:'DELETE'
response_delete = urllib2.urlopen(request_delete).read()
print(response_delete)