Say hello to Elasticsearchedit

Almost all of the methods on the client accept two arguments:

  • params - an optional object/hash of parameters More info here.
  • callback - an optional function that will be called with the final result of the method. When omitted, a promise is returned. More info here.

Ping the clusteredit

Send a HEAD request to "/" and allow up to 30 seconds for it to complete.{
  requestTimeout: 30000,
}, function (error) {
  if (error) {
    console.error('elasticsearch cluster is down!');
  } else {
    console.log('All is well');

Use Promisesedit

Skip the callback to get a promise back.{
  q: 'pants'
}).then(function (body) {
  var hits = body.hits.hits;
}, function (error) {

Allow 404 responsesedit

Prevent 404 responses from being considered errors by telling the client to ignore them.

  index: 'test_index',
  ignore: [404]
}).then(function (body) {
  // since we told the client to ignore 404 errors, the
  // promise is resolved even if the index does not exist
  console.log('index was deleted or never existed');
}, function (error) {
  // oh no!