microblog
microblog copied to clipboard
Verify if elastic server is running
Hi Miguel,
I have a suggestion: in the application factory, check not only for the elastic env variable, but also if the elastic server is actually running.
The code extract from my own project:
if app.config['ELASTICSEARCH_URL']: es = Elasticsearch([app.config['ELASTICSEARCH_URL']]) app.elasticsearch = es if es.ping() else None else: app.elasticsearch = None
Looks like Github didn't preserve the code indentation, so here's a picture of it:

This is fine, but if the application is configured to use elasticsearch I think it is better that errors are generated, which will alert you that you have an issue with elasticsearch, instead of silently disabling all the search functionality.
I see your point.
In my case I have modified also the search() route function, where I do an abort(500) if elasticsearch attribute is set to None.
This way it is clear that something went wrong, and no low level detail is exposed.