Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Handling elasticsearch exception

Im using python elastic search module and need to handle exception.

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

but I get this error -

AttributeError: 'Elasticsearch' object has no attribute 'ElasticsearchException'
like image 948
user1050619 Avatar asked Feb 10 '16 17:02

user1050619


1 Answers

As the error points out ElasticsearchException is not an attribute of Elasticsearch object . From the documentation it is a class in elasticsearch module

So the example code should look something on these lines :

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'
like image 133
keety Avatar answered Nov 19 '22 02:11

keety