in src/elasticSearchService.ts [314:349]
private async executeQuery(
searchQuery: Query,
request: TypeSearchRequest,
): Promise<{ hits: any[]; total: number }> {
try {
const searchQueryWithAlias = {
...searchQuery.queryRequest,
index: getAliasName(searchQuery.resourceType, request.tenantId),
...(request.sessionId && { preference: request.sessionId }),
};
if (logger.isDebugEnabled()) {
logger.debug(`Elastic search query: ${JSON.stringify(searchQueryWithAlias, null, 2)}`);
}
const apiResponse = await this.esClient.search(searchQueryWithAlias);
return {
total: apiResponse.body.hits.total.value,
hits: apiResponse.body.hits.hits,
};
} catch (error) {
// Indexes are created the first time a resource of a given type is written to DDB.
if (error instanceof ResponseError && error.meta.body.error.type === 'index_not_found_exception') {
logger.info(
`Search index for ${getAliasName(
searchQuery.resourceType,
request.tenantId,
)} does not exist. Returning an empty search result`,
);
return {
total: 0,
hits: [],
};
}
throw error;
}
}