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 ?