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

118
Vistas
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 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