From ad405032a82508021637f9d80a5c4fb08c77e115 Mon Sep 17 00:00:00 2001 From: Vacha Shah Date: Tue, 31 Oct 2023 06:45:15 +0000 Subject: [PATCH] Making Hit.id nullable when storedFields is none Signed-off-by: Vacha Shah --- .../client/opensearch/core/search/Hit.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/core/search/Hit.java b/java-client/src/main/java/org/opensearch/client/opensearch/core/search/Hit.java index 0050f9da69..6fabb4100a 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/core/search/Hit.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/core/search/Hit.java @@ -108,7 +108,7 @@ public class Hit implements JsonpSerializable { private Hit(Builder builder) { this.index = ApiTypeHelper.requireNonNull(builder.index, this, "index"); - this.id = ApiTypeHelper.requireNonNull(builder.id, this, "id"); + this.id = builder.id; this.score = builder.score; this.explanation = builder.explanation; this.fields = ApiTypeHelper.unmodifiable(builder.fields); @@ -141,8 +141,9 @@ public final String index() { } /** - * Required - API name: {@code _id} + * API name: {@code _id} */ + @Nullable public final String id() { return this.id; } @@ -283,8 +284,10 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { generator.writeKey("_index"); generator.write(this.index); - generator.writeKey("_id"); - generator.write(this.id); + if (this.id != null) { + generator.writeKey("_id"); + generator.write(this.id); + } if (this.score != null) { generator.writeKey("_score"); @@ -418,6 +421,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { public static class Builder extends ObjectBuilderBase implements ObjectBuilder> { private String index; + @Nullable private String id; @Nullable @@ -480,9 +484,9 @@ public final Builder index(String value) { } /** - * Required - API name: {@code _id} + * API name: {@code _id} */ - public final Builder id(String value) { + public final Builder id(@Nullable String value) { this.id = value; return this; }