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

117
Visualizações
How use Async await in Elastic Search

I have the code like this:

await personalizeRuntime.getRecommendations(
      {
        campaignArn,
        userId: "abc",
      },
      async (err, data) => {
        if (err) {
          console.error("ERR: ", err);
        }

        const mapData = data.itemList.map((a) => {
          a.timestamp = Math.floor(Date.now() / 1000);
          a.userId = "abc";
          return a;
        });

        const body = mapData.flatMap((doc, index) => [
          { index: { _index: "recommendation-engines", _id: index + 1 } },
          doc,
        ]);

        await client.bulk({ body: body, refresh: true});

        const checkDataIndex = await client.search({
          index: "recommendation-engines",
        });
    
        console.log('checkDataIndex', checkDataIndex);
      }
    )

    const checkDataIndex2 = await client.search({
      index: "recommendation-engines",
    });

    console.log('checkDataIndex2', checkDataIndex2);

But the result always print checkDataIndex2 first and checkDataIndex2 have null array in checkDataIndex2.hits.hits

checkDataIndex2 {
  body: {
    took: 4,
    timed_out: false,
    _shards: { total: 1, successful: 1, skipped: 0, failed: 0 },
    hits: { total: [Object], max_score: null, hits: [] }
  },
}

checkDataIndex {
  body: {
    took: 4,
    timed_out: false,
    _shards: { total: 1, successful: 1, skipped: 0, failed: 0 },
    hits: { total: [Object], max_score: 1, hits: [Array] }
  },
}

Can you fix my problem when the expected result is show query search in checkDataIndex2.hits.hits ?

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