Skip to content

Commit

Permalink
Fix elasticsearch NRE when no results are found. (#16919)
Browse files Browse the repository at this point in the history
TopDocs returns null and the where clause causes NRE
  • Loading branch information
PBMikeW authored Oct 31, 2024
1 parent b588d50 commit 773c11c
Showing 1 changed file with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,16 @@ public async Task<IQueryResults> ExecuteQueryAsync(Query query, IDictionary<stri
var docs = await _queryService.SearchAsync(metadata?.Index, tokenizedContent);
elasticQueryResults.Count = docs.Count;

if (query.ReturnContentItems)
// We always return an empty collection if the bottom lines queries have no results.
elasticQueryResults.Items = [];

if (elasticQueryResults.Count == 0 || docs.TopDocs == null || docs.TopDocs.Count == 0)
{
// We always return an empty collection if the bottom lines queries have no results.
elasticQueryResults.Items = [];
return elasticQueryResults;
}

if (query.ReturnContentItems)
{
// Load corresponding content item versions.
var topDocs = docs.TopDocs.Where(x => x != null).ToList();

Expand Down

0 comments on commit 773c11c

Please sign in to comment.