Does the javascript elasticsearch client have health checks?

Hi everyone,

I've set up 3 elasticsearch nodes that are booth master and data nodes.

I have a node js application that points to these nodes with this configuration

   var ESDB = function () {
	this.client = new elasticsearch.Client({
		keepAlive: true,
		hosts: process.env.ESDB.split(","),
		httpAuth: process.env.ESDB_PASSWORD,
		requestTimeout: 20000,
		log: [{
			type: 'stdio',
			levels: ['error']
		ssl: {
			ca: fs.readFileSync(process.env.CA),
			rejectUnauthorized: true

The process.env.ESDB contains a string of hosts that are separated by a "," which i then make into an array by using the .split() method.

I then export the client to use it in other files.

I had an incident where one of my nodes went down and it had something to do with Azure having some problems on their end. However i could not use the elasticsearch client in my node.js application during the time that it was down as it was still pointing to the node that went down.

Does the elasticsearch javascript client haven any configuration for adding health checks to see which one of the nodes is alive? I know it does load-balancing I'm just not sure weather it does health checks in order to avoid nodes that are down.

If not is there any way i can load-balance my nodes and perform health checks on them in order to avoid service disruptions like the one i just mentioned? Would a coordinator node do the trick?

The client has an internal connection pool, and when it detects that a node is malfunctioning (5xx responses, timeout, connection faults...) it will mark it as dead, and remove it from the node rotation (round-robin by default). Once a node is dead, it will try every now and then to ping the node, to verify if it's back operational.

What do you mean with "I could not use elasticsearch client"?

Finally, it appears you are using the legacy Node.js client, I strongly recommend migrating to the new one, you can find the migration guide here.

Thank you for pointing out the new node.js client. I should probably start migrating to the new one right away.

Sorry for not being descriptive enough when i said i could not use the client.

I actually meant that the client was still sending requests to the node that went down and my users would sometimes see errors that something is not working at the moment when using my node.js application. I guess it takes a bit of time until the client realizes that the node went down?

Or since I'm using the legacy client it might not have worked as expected since the client was still sending requests to the node that went down for about 5 minutes until i manually removed it from the hosts that it should point to.

Thank you again for your response.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.