user3284007
user3284007

Reputation: 1717

Query ElasticSearch From Node.js

I have a Node.js application. I need to query an ElasticSearch instance that's running on http://myserver.com to see if it still "alive". I'm trying to identify two things:

  1. What is the most performant way to query ElasticSearch from Node.js? I know I can run queries against ElasticSearch in PostMan. For that reason, I think I can just use the http module in node. Yet, I'm not sure if this is really the most performant approach.

  2. What is the smallest query I can run against ElasticSearch just to see if its running? I know if I was hitting a SQL database, I could just use SELECT 1. Is there something similar in ElasticSearch?

Thank you so much for your help!

Upvotes: 0

Views: 1188

Answers (1)

progrrammer
progrrammer

Reputation: 4489

For nodejs, you can use. Elasticsearch client elasticsearchjs

And, You can ping the cluster to see if it is running.

ie.

client.ping({
  requestTimeout: 1000,
  // undocumented params are appended to the query string
  hello: "elasticsearch!"
}, function (error) {
  if (error) {
    console.error('elasticsearch cluster is down!');
  } else {
    console.log('All is well');
  }
});

I think that helps, Good luck in starting elasticsearch in nodejs.

Upvotes: 1

Related Questions