python - 处理 Elasticsearch 异常

标签 python elasticsearch

我正在使用 python Elasticsearch 模块,需要处理异常。

try:
    es.index(index='tickets', doc_type='tickets', body=doc)
except es.ElasticsearchException as es1:
    print 'error'

但我得到这个错误 -

AttributeError: 'Elasticsearch' object has no attribute 'ElasticsearchException'

最佳答案

由于错误指出 ElasticsearchException 不是 Elasticsearch 对象的属性。 来自documentation它是 elasticsearch 模块中的一个类

所以示例代码应该看起来像这些行:

import elasticsearch
es = elasticsearch.Elasticsearch()
es.index(index='tickets', doc_type='tickets', body=doc)
try :
    es.indices.create(index='test-index', ignore=400)
except elasticsearch.ElasticsearchException as es1:
    print 'error'

关于python - 处理 Elasticsearch 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35322292/

相关文章:

python - 是否有适用于 Python 2.2 的带有 HTTPCookieProcessor 函数的 urllib2 模块?

elasticsearch - Elasticsearch适用于少用词的文档

javascript - 如何在 Node js Controller 文件中引用 Elastic Search JavaScript 客户端库

geolocation - 为什么我的ElasticSearch查询没有获取位于地理边界框内的文档?

java - 基于_source字段搜索查询elasticsearch

python - 使用自定义索引重新分区 Dask Dataframe

python - 对 Pandas Dataframe 列中的列表进行排序

python - 在 Python 中,in 运算符是如何实现的?它是否使用迭代器的 next() 方法?

python - 在基于另一列的列中重复值

elasticsearch - elastic4s 搜索 id