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'
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'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With