Skip to content

Commit

Permalink
Making Hit.id nullable when storedFields is none
Browse files Browse the repository at this point in the history
Signed-off-by: Vacha Shah <[email protected]>
  • Loading branch information
VachaShah committed Oct 31, 2023
1 parent 5b1e295 commit ad40503
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public class Hit<TDocument> implements JsonpSerializable {
private Hit(Builder<TDocument> 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);
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -418,6 +421,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
public static class Builder<TDocument> extends ObjectBuilderBase implements ObjectBuilder<Hit<TDocument>> {
private String index;

@Nullable
private String id;

@Nullable
Expand Down Expand Up @@ -480,9 +484,9 @@ public final Builder<TDocument> index(String value) {
}

/**
* Required - API name: {@code _id}
* API name: {@code _id}
*/
public final Builder<TDocument> id(String value) {
public final Builder<TDocument> id(@Nullable String value) {
this.id = value;
return this;
}
Expand Down

0 comments on commit ad40503

Please sign in to comment.