I'd like a simple way of verifying that ES is available to a Java client. I have a factory that looks something like this to get a client instance:
https://gist.github.com/1364734
What's the best way to gracefully handle the scenario of ES not being available or is what I have sufficient?
Shay previously confirmed that this approach is a good one. The approach is backed up by the documentation as well .
As for gracefully handling. You should just error the request or process that is attempting to execute the search. It's possible the TransportClient
becomes connected and future requests may succeed.
Copying your function here for the sake of completeness.
private void verifyConnection(TransportClient client) { ImmutableList<DiscoveryNode> nodes = client.connectedNodes(); if (nodes.isEmpty()) { throw new ElasticSearchUnavailableException("No nodes available. Verify ES is running!"); } else { log.info("connected to nodes: " + nodes.toString()); } }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.