Eugene Goldberg
Eugene Goldberg

Reputation: 15544

How to list ALL indices using elasticsearch.js client

I need to list all indices in my node.js app, using elasticsearch.js node module. What I have is:

var elasticsearch = require('elasticsearch');
var client = new elasticsearch.Client({
  host: 'localhost:9200',
  log: 'trace'
});

  client.indices.get({

  })

The error I get is:

(node:72002) UnhandledPromiseRejectionWarning: TypeError: Unable to build a path with those params. Supply at least index

What is the proper syntax for client.indices.get, which would list all available indices?

Upvotes: 2

Views: 1283

Answers (1)

Sathishkumar
Sathishkumar

Reputation: 3733

Try like this

const indices = await client.cat.indices({format: 'json'})
console.log('indices:', indices)

or else

client.cat.indices("b",function(r,q){
  console.log(r,q);
}) }]);

Hope it helps.

Upvotes: 3

Related Questions