Reputation: 20856
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
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