diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/core/bulk/UpdateOperation.java b/java-client/src/main/java/org/opensearch/client/opensearch/core/bulk/UpdateOperation.java index 15d30fe0c4..3e55a900b4 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/core/bulk/UpdateOperation.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/core/bulk/UpdateOperation.java @@ -32,11 +32,12 @@ package org.opensearch.client.opensearch.core.bulk; -import jakarta.json.stream.JsonGenerator; import java.util.Arrays; import java.util.Iterator; import java.util.function.Function; + import javax.annotation.Nullable; + import org.opensearch.client.json.JsonpMapper; import org.opensearch.client.json.JsonpSerializer; import org.opensearch.client.json.NdJsonpSerializable; @@ -44,6 +45,8 @@ import org.opensearch.client.util.ApiTypeHelper; import org.opensearch.client.util.ObjectBuilder; +import jakarta.json.stream.JsonGenerator; + // typedef: _global.bulk.UpdateOperation public class UpdateOperation extends BulkOperationBase implements NdJsonpSerializable, BulkOperationVariant { @@ -69,7 +72,8 @@ private UpdateOperation(Builder builder) { } - public static UpdateOperation of(Function, ObjectBuilder>> fn) { + public static UpdateOperation + of(Function, ObjectBuilder>> fn) { return fn.apply(new Builder<>()).build(); } @@ -102,6 +106,7 @@ public final Integer retryOnConflict() { return this.retryOnConflict; } + @Override protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { super.serializeInternal(generator, mapper); @@ -125,7 +130,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { public static class Builder extends BulkOperationBase.AbstractBuilder> implements - ObjectBuilder> { + ObjectBuilder> { private UpdateOperationData data; @@ -144,6 +149,9 @@ public static class Builder extends BulkOperationBase.AbstractBuilder @Nullable private Boolean docAsUpsert; + @Nullable + private Boolean scriptedUpsert; + @Nullable private TDocument upsert; @@ -166,6 +174,14 @@ public final Builder docAsUpsert(@Nullable Boolean value) { return this; } + /** + * API name: {@code scripted_upsert} + */ + public final Builder scriptedUpsert(@Nullable Boolean value) { + this.scriptedUpsert = value; + return this; + } + /** * API name: {@code upsert} */ @@ -218,17 +234,19 @@ protected Builder self() { * @throws NullPointerException * if some of the required fields are null. */ + @Override public UpdateOperation build() { _checkSingleUse(); data = new UpdateOperationData.Builder().document(document) .docAsUpsert(docAsUpsert) + .scriptedUpsert(scriptedUpsert) .script(script) .upsert(upsert) .tDocumentSerializer(tDocumentSerializer) .build(); - return new UpdateOperation(this); + return new UpdateOperation<>(this); } } diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/core/bulk/UpdateOperationData.java b/java-client/src/main/java/org/opensearch/client/opensearch/core/bulk/UpdateOperationData.java index 572930d0fd..832ab5753d 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/core/bulk/UpdateOperationData.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/core/bulk/UpdateOperationData.java @@ -24,6 +24,9 @@ public class UpdateOperationData implements JsonpSerializable { @Nullable private final Boolean docAsUpsert; + @Nullable + private final Boolean scriptedUpsert; + @Nullable private final TDocument upsert; @@ -36,6 +39,7 @@ public class UpdateOperationData implements JsonpSerializable { private UpdateOperationData(Builder builder) { this.document = builder.document; this.docAsUpsert = builder.docAsUpsert; + this.scriptedUpsert = builder.scriptedUpsert; this.script = builder.script; this.upsert = builder.upsert; this.tDocumentSerializer = builder.tDocumentSerializer; @@ -55,6 +59,11 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { generator.write(this.docAsUpsert); } + if (this.scriptedUpsert != null) { + generator.writeKey("scripted_upsert"); + generator.write(scriptedUpsert); + } + if (this.document != null) { generator.writeKey("doc"); JsonpUtils.serialize(document, generator, tDocumentSerializer, mapper); @@ -87,6 +96,9 @@ public static class Builder extends BulkOperationBase.AbstractBuilder @Nullable private Boolean docAsUpsert; + @Nullable + private Boolean scriptedUpsert; + @Nullable private TDocument upsert; @@ -109,6 +121,14 @@ public final Builder docAsUpsert(@Nullable Boolean value) { return this; } + /** + * API name: {@code scripted_upsert} + */ + public final Builder scriptedUpsert(@Nullable Boolean value) { + this.scriptedUpsert = value; + return this; + } + /** * API name: {@code upsert} */