Hello,
I am using Kibana to load list of hits by index name using ElasticSearch API.
The best way to do that, is using Scroll API and this is my routes.js code:
const elasticsearch = require('elasticsearch');
export default function (server) {
const config = server.config();
const client = new elasticsearch.Client({ host: config.get('elasticsearch.url') });
server.route({
path: '/api/indices_view/index/{name}',
method: 'GET',
handler(req, reply) {
const allHits = [];
const responseQueue = [];
// start things off by searching, setting a scroll timeout, and pushing
// our first response into the queue to be processed
client.search({
index: 'shakespeare',
scroll: '30s', // keep the search results "scrollable" for 30 seconds
q: 'type:act'
})
while (responseQueue.length) {
const response = responseQueue.shift();
// collect the titles from this response
response.hits.hits.forEach(function (hit) {
allHits .push(hit.fields.title);
});
// check to see if we have collected all of the titles
if (response.hits.total === allHits .length) {
console.log('every "test" title', allHits );
break
}
// get the next response if there are more titles to fetch
responseQueue.push(
client.scroll({
scrollId: response._scroll_id,
scroll: '30s'
})
);
}
}
});
}
I know.. the example uses Await operator. If I use it, I got this error in my console await is a reserved word, else I got nothing.
I'll appreciate any help
Best regards.