如何使用Python查询检查索引是否存在?
我将我的索引作为变量传递给查询,如下所示:
i=int(datetime.datetime.now().strftime('%d'))+1
indextring="index"
for m in range (i-10,i):
d = datetime.datetime(2016, 10, m, 18, 00).strftime('%Y-%m-%d')
index1=datestring+d
subfix="_"+datetime.datetime(2016, 10, m, 18, 00).strftime('%Y-%m-%d')
es=Elasticsearch(['localhost:9200'])
res = **es.search(index='{0}'.format(index1)**, doc_type="log",size=10000, from_=0, body={ "query": {
"match": {
....Match condition follows
}
}
}})
现在,某些索引在特定日期不存在,但我希望该过程可以不考虑此问题而继续运行。当索引不存在时,我会收到以下错误消息-->
elasticsearch.exceptions.NotFoundError: TransportError(404, u'index_not_found_exception')
我不确定在elasticsearch中如何处理异常。
exists
API调用来检查索引是否存在。 - Val