user1050619
user1050619

Reputation: 20856

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'

Upvotes: 8

Views: 22925

Answers (1)

keety
keety

Reputation: 17441

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'

Upvotes: 19

Related Questions