Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

210
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda