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

116
Views
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
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!