Skip to content

Commit 32cf03e

Browse files
authored
Improve SearchHit "equals" implementation for null fields cases (#50327)
* Improve SearchHit "equals" implementation for null fields cases
1 parent 2e149c9 commit 32cf03e

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

server/src/main/java/org/elasticsearch/search/SearchHit.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ public boolean equals(Object obj) {
887887
&& Objects.equals(seqNo, other.seqNo)
888888
&& Objects.equals(primaryTerm, other.primaryTerm)
889889
&& Objects.equals(source, other.source)
890-
&& Objects.equals(fields, other.fields)
890+
&& Objects.equals(getFields(), other.getFields())
891891
&& Objects.equals(getHighlightFields(), other.getHighlightFields())
892892
&& Arrays.equals(matchedQueries, other.matchedQueries)
893893
&& Objects.equals(explanation, other.explanation)

server/src/test/java/org/elasticsearch/search/SearchHitTests.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,12 @@ public static SearchHit createTestItem(XContentType xContentType, boolean withOp
7171
if (randomBoolean()) {
7272
nestedIdentity = NestedIdentityTests.createTestItem(randomIntBetween(0, 2));
7373
}
74-
Map<String, DocumentField> fields = new HashMap<>();
75-
if (randomBoolean()) {
76-
fields = GetResultTests.randomDocumentFields(xContentType).v2();
74+
Map<String, DocumentField> fields = null;
75+
if (frequently()) {
76+
fields = new HashMap<>();
77+
if (randomBoolean()) {
78+
fields = GetResultTests.randomDocumentFields(xContentType).v2();
79+
}
7780
}
7881
SearchHit hit = new SearchHit(internalId, uid, nestedIdentity, fields);
7982
if (frequently()) {

0 commit comments

Comments
 (0)