8

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'
1
  • didn't get a chance too try but think it should be except elasticsearch.ElasticsearchException as es1 and not es.ElasticsearchException Commented Feb 10, 2016 at 18:09

1 Answer 1

19

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'
Sign up to request clarification or add additional context in comments.

4 Comments

This is no longer a relevant solution. My elasticsearch module does not have a top level attribute ElasticsearchException
@AaronSoellinger, I have the same issue, could you pls tell me how you solved this problem? Thanks
from elasticsearch import ElasticsearchException works for me with elasticsearch==7.8.0
Anyone have the solution for v8?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.