Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

205
Views
Fetch more than 10000 result from elasticsearch with node.js using search_after

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"
  }
}

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!