内容简介:翻译自:https://stackoverflow.com/questions/40300231/how-to-check-if-an-index-exists-in-elasticsearch-using-a-python-script-and-perfo
查询检查索引是否存在?
我将我的索引作为在查询外部分配的变量传递为: –
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中是如何工作的.
,它告诉您索引中是否存在给定文档而不是索引本身.
试试这个代码
if es.indices.exists(index="index"):
Your code for search
如果你想使用还有更多 options .
翻译自:https://stackoverflow.com/questions/40300231/how-to-check-if-an-index-exists-in-elasticsearch-using-a-python-script-and-perfo
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Python 3学习笔记(上卷)
雨痕 / 电子工业出版社 / 2018-1 / 89
经过9 年的发展,Python 3 生态已相当成熟。无论是语言进化、解释器性能提升,还是第三方支持,都是如此。随着Python 2.7 EOF 日趋临近,迁移到Python 3 的各种障碍也被逐一剔除。是时候在新环境下学习或工作了。 人们常说Python 简单易学,但这是以封装和隐藏复杂体系为代价的。仅阅读语言规范很难深入,亦无从发挥其应有能力,易学难精才是常态。《Python 3学习笔记(......一起来看看 《Python 3学习笔记(上卷)》 这本书的介绍吧!