| endpoint | ping |
|---|---|
| lang | javascript |
| es_version | 9.3 |
| client | @elastic/elasticsearch@9.3.0 |
Use client.ping() to check whether the Elasticsearch server is
reachable. Returns true if the server responds, false otherwise.
const alive = await client.ping();
if (alive) {
console.log("Elasticsearch is available");
} else {
console.log("Elasticsearch is not reachable");
}Use ping at application startup to fail fast if Elasticsearch is
unavailable:
const alive = await client.ping();
if (!alive) {
console.error("Cannot connect to Elasticsearch — exiting");
process.exit(1);
}