From d5cec7faa109e23b0bcb59db6dba623ada9d9156 Mon Sep 17 00:00:00 2001 From: Aleksandr Maus Date: Mon, 23 Dec 2019 09:59:07 -0500 Subject: [PATCH] Improve SearchHit "equals" implementation for null fields cases (#50327) (#50448) * Improve SearchHit "equals" implementation for null fields cases --- .../main/java/org/elasticsearch/search/SearchHit.java | 2 +- .../java/org/elasticsearch/search/SearchHitTests.java | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/search/SearchHit.java b/server/src/main/java/org/elasticsearch/search/SearchHit.java index 37de200dbba..2c56c713bb8 100644 --- a/server/src/main/java/org/elasticsearch/search/SearchHit.java +++ b/server/src/main/java/org/elasticsearch/search/SearchHit.java @@ -906,7 +906,7 @@ public final class SearchHit implements Writeable, ToXContentObject, Iterable { if (randomBoolean()) { nestedIdentity = NestedIdentityTests.createTestItem(randomIntBetween(0, 2)); } - Map fields = new HashMap<>(); - if (randomBoolean()) { - fields = GetResultTests.randomDocumentFields(xContentType).v2(); + Map fields = null; + if (frequently()) { + fields = new HashMap<>(); + if (randomBoolean()) { + fields = GetResultTests.randomDocumentFields(xContentType).v2(); + } } SearchHit hit = new SearchHit(internalId, uid, type, nestedIdentity, fields); if (frequently()) {