Skip to content

Fix #8340: Prevent null reference exception in SearchResponse<T> #8466

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Elasticsearch B.V licenses this file to you under the Apache 2.0 License.
// See the LICENSE file in the project root for more information.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;
Expand All @@ -11,10 +12,10 @@ namespace Elastic.Clients.Elasticsearch;
public partial class SearchResponse<TDocument>
{
[JsonIgnore]
public IReadOnlyCollection<Core.Search.Hit<TDocument>> Hits => HitsMetadata.Hits;
public IReadOnlyCollection<Core.Search.Hit<TDocument>> Hits => HitsMetadata?.Hits ?? [];

[JsonIgnore]
public IReadOnlyCollection<TDocument> Documents => HitsMetadata.Hits.Select(s => s.Source).ToReadOnlyCollection();
public IReadOnlyCollection<TDocument> Documents => HitsMetadata?.Hits?.Select(s => s.Source).ToReadOnlyCollection() ?? [];

[JsonIgnore]
public long Total => HitsMetadata?.Total?.Item1?.Value ?? HitsMetadata?.Total?.Item2 ?? -1;
Expand Down