内容简介:翻译自: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
以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网
猜你喜欢:- 通过shell脚本为mongodb建立索引
- MySQL索引使用说明(单列索引和多列索引)
- Elasticsearch索引的基本操作(3)-索引的滚动索引
- Coreseek 增量索引模拟实时索引
- Coreseek 增量索引模拟实时索引
- MySQL高效索引之覆盖索引
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Introduction to Computation and Programming Using Python
John V. Guttag / The MIT Press / 2013-7 / USD 25.00
This book introduces students with little or no prior programming experience to the art of computational problem solving using Python and various Python libraries, including PyLab. It provides student......一起来看看 《Introduction to Computation and Programming Using Python》 这本书的介绍吧!