in lambda/es-proxy-layer/lib/kendraQuery.js [122:168]
await asyncForEach(resArray, async function (res) {
if (res && res.ResultItems && res.ResultItems.length > 0) {
var i, element;
for (i=0; i<res.ResultItems.length; i++) {
element = res.ResultItems[i];
if(!confidence_filter(request_params.minimum_score,element))
continue;
/* Note - only FAQ format will be provided back to the requester */
if (element.Type === 'QUESTION_ANSWER' && foundAnswerCount < request_params.size && element.AdditionalAttributes &&
element.AdditionalAttributes.length > 1) {
if (!open_es.hasJsonStructure(element.DocumentURI)) {
break;
}
var hit = JSON.parse(element.DocumentURI);
if (_.get(hit,"_source_qid")) {
let qid = hit._source_qid ;
// FAQ only references the QID but doesn't contain the full docunment.. retrieve it from ES
qnabot.log("Kendra matched qid: ", qid, ". Retrieving full document from Elasticsearch.");
let es_response = await open_es.run_qid_query_es(request_params, qid) ;
qnabot.log("Qid document from Kendra: ", JSON.stringify(hit));
hit = _.get(es_response, "hits.hits[0]._source"); //todo fix if null -- test from content designer
if(hit == null){
qnabot.log("WARNING: An answer was found in Kendrs FAQ, but a corresponding answer was not found in ElasticSearch for "+ hit)
continue;
}
if(_.get(hit,"QNAClientFilter")){
qnabot.log("Found an answer with a clientFilterValue set...skipping")
continue;
}
}
qnabot.log(`hit is ${JSON.stringify(hit)}`);
json_struct.push(hit);
kendraQueryId = res.QueryId; // store off the QueryId to use as a session attribute for feedback
kendraIndexId = res.originalKendraIndexId; // store off the Kendra IndexId to use as a session attribute for feedback
kendraResultId = element.Id; // store off resultId to use as a session attribute for feedback
foundAnswerCount++;
}
}
}
});