How to check if ElasticSearch client is connected? How to check if ElasticSearch client is connected? elasticsearch elasticsearch

How to check if ElasticSearch client is connected?


Getting stats can be a heavy call to simply ensure your client is connected. You should use ping, see 2nd example https://github.com/elastic/elasticsearch-js#examples

We are using ping too, after instantiating elasticsearch-js client connection on start up.

// example from above linkvar elasticsearch = require('elasticsearch');var client = new elasticsearch.Client({  host: 'localhost:9200',  log: 'trace'});client.ping({  // ping usually has a 3000ms timeout  requestTimeout: Infinity,  // undocumented params are appended to the query string  hello: "elasticsearch!"}, function (error) {  if (error) {    console.trace('elasticsearch cluster is down!');  } else {    console.log('All is well');  }});