From bfaf353971c19d1ab30bc2231caa66d729942944 Mon Sep 17 00:00:00 2001 From: Christian Winkler Date: Mon, 27 Nov 2023 15:29:58 +0100 Subject: [PATCH] Added detectNoop option to UpdateOperation (#744) --- .../opensearch/core/bulk/UpdateOperation.java | 12 +++++++ .../core/bulk/UpdateOperationData.java | 31 ++++++++++++++++--- 2 files changed, 39 insertions(+), 4 deletions(-) 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 3e55a900b4..473fe3bd5e 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 @@ -152,6 +152,9 @@ public static class Builder extends BulkOperationBase.AbstractBuilder @Nullable private Boolean scriptedUpsert; + @Nullable + private Boolean detectNoop; + @Nullable private TDocument upsert; @@ -182,6 +185,14 @@ public final Builder scriptedUpsert(@Nullable Boolean value) { return this; } + /** + * API name: {@code detect_noop} + */ + public final Builder detectNoop(@Nullable Boolean value) { + this.detectNoop = value; + return this; + } + /** * API name: {@code upsert} */ @@ -241,6 +252,7 @@ public UpdateOperation build() { data = new UpdateOperationData.Builder().document(document) .docAsUpsert(docAsUpsert) .scriptedUpsert(scriptedUpsert) + .detectNoop(detectNoop) .script(script) .upsert(upsert) .tDocumentSerializer(tDocumentSerializer) 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 832ab5753d..7f99ecf6af 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 @@ -8,8 +8,8 @@ package org.opensearch.client.opensearch.core.bulk; -import jakarta.json.stream.JsonGenerator; import javax.annotation.Nullable; + import org.opensearch.client.json.JsonpMapper; import org.opensearch.client.json.JsonpSerializable; import org.opensearch.client.json.JsonpSerializer; @@ -17,6 +17,8 @@ import org.opensearch.client.opensearch._types.Script; import org.opensearch.client.util.ObjectBuilder; +import jakarta.json.stream.JsonGenerator; + public class UpdateOperationData implements JsonpSerializable { @Nullable private final TDocument document; @@ -27,6 +29,9 @@ public class UpdateOperationData implements JsonpSerializable { @Nullable private final Boolean scriptedUpsert; + @Nullable + private final Boolean detectNoop; + @Nullable private final TDocument upsert; @@ -40,6 +45,7 @@ private UpdateOperationData(Builder builder) { this.document = builder.document; this.docAsUpsert = builder.docAsUpsert; this.scriptedUpsert = builder.scriptedUpsert; + this.detectNoop = builder.detectNoop; this.script = builder.script; this.upsert = builder.upsert; this.tDocumentSerializer = builder.tDocumentSerializer; @@ -64,6 +70,11 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { generator.write(scriptedUpsert); } + if (this.detectNoop != null) { + generator.writeKey("detect_noop"); + generator.write(scriptedUpsert); + } + if (this.document != null) { generator.writeKey("doc"); JsonpUtils.serialize(document, generator, tDocumentSerializer, mapper); @@ -85,7 +96,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { */ public static class Builder extends BulkOperationBase.AbstractBuilder> implements - ObjectBuilder> { + ObjectBuilder> { @Nullable private TDocument document; @@ -99,6 +110,9 @@ public static class Builder extends BulkOperationBase.AbstractBuilder @Nullable private Boolean scriptedUpsert; + @Nullable + private Boolean detectNoop; + @Nullable private TDocument upsert; @@ -128,7 +142,15 @@ public final Builder scriptedUpsert(@Nullable Boolean value) { this.scriptedUpsert = value; return this; } - + + /** + * API name: {@code detect_noop} + */ + public final Builder detectNoop(@Nullable Boolean value) { + this.detectNoop = value; + return this; + } + /** * API name: {@code upsert} */ @@ -165,10 +187,11 @@ protected Builder self() { * @throws NullPointerException * if some of the required fields are null. */ + @Override public UpdateOperationData build() { _checkSingleUse(); - return new UpdateOperationData(this); + return new UpdateOperationData<>(this); } } }