I'm trying to fetch more than 10,000 records from elasticsearch, using 'search_after'. In the official documentation it's was implemented outside the body, but that gave me error. So i did some search and found out that, it should be used under body. I've tried to implement it but, i'm only getting 10,000 results. Also i'm not able to find the pit id in my response. Can anyone help me with this..??
I'm posting my code below:
var client = new elasticsearch.Client({
host: elasticUrl,
});
const getElasticData = async() => {
const response = await client.search({
index: index,
type: '_doc',
// size: 10000,
body: {
query: {
match_all: {},
},
query: {
match_all: {},
},
sort: [
{
"_id": {
"order": "asc"
}
}
],
search_after: [10000]
}
})
return response
}
let completeElasticData;
getElasticData().then(res => {
completeElasticData = res
let displayMsg = completeElasticData ? `Data fetched from elastic: [ ${completeElasticData.hits.total.value} ]` : `something went wrong`
console.log(displayMsg)
app.get('/', (req, res)=>{
res.send(completeElasticData)
})
}).catch(err => console.log(err));
app.listen(5000, () => console.log('Server started on port 5000'));
Below is the view to package.json
{
"name": "elasticdata",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "nodemon app.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"elasticsearch": "^16.7.2",
"express": "^4.17.2",
"nodemon": "^2.0.15"
}
}