Search code examples
node.jselasticsearchelastic-stack

Retrieving GET /stats of Elastic search using NodeJS client


I can easily get this elasticsearch command (GET /_stats) response on my local environment using kibana. I however need to run the command on node.js server. I have tried the following but it doesn't work, rather it throws error. Can anyone help me on this please?

const client = new Client({
 node: process.env.ES_URL,
 auth: {
 username: process.env.ES_USER,
 password: process.env.ES_PASSWORD,
  },
});
const stats = await client.stats();
...
//The error response is TypeError: client.stats is not a function

PS: Using this command returns the same result on Kibana (GET _cluster/health)

const {body} = await client.cluster.health({});


Solution

  • Have you tried client.cluster.stats() instead?