| endpoint | ping |
|---|---|
| lang | java |
| es_version | 9.3 |
| client | co.elastic.clients:elasticsearch-java:9.3.0 |
Use client.ping() to check whether the Elasticsearch server is
reachable.
boolean alive = client.ping().value();
if (alive) {
System.out.println("Elasticsearch is available");
} else {
System.out.println("Elasticsearch is not reachable");
}Use ping at application startup to fail fast if Elasticsearch is
unavailable:
if (!client.ping().value()) {
System.err.println("Cannot connect to Elasticsearch — exiting");
System.exit(1);
}