Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

213
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda