In my node.js app, I'm trying to build a list of all elasticsearch indices and send this list as JSON to my Angular app. I'm using elasticsearch.js module:
npm install elasticsearch
const elasticsearch = require('elasticsearch');
const client = new elasticsearch.Client({
host: 'localhost:9200',
log: 'trace'
});
Then, in my REST API route handler, I'm pinging elasticsearch, and running a query, which suppose to return all indices:
indexRoutes.route('/').get(function (req, res) {
client.ping({
requestTimeout: 30000,
}, function (error) {
if (error) {
console.error('elasticsearch cluster is down!');
} else {
console.log('All is well');
client.cat.indices({format: 'json'})
.then(console.log(index));
}
});
});
I assume, that once the promise is resolved, there would be an object returned from it, so I'm referencing that object as "index", but only getting the error "index is not defined".
What is the proper way to obtain such listing and assign the result to a String?