diff --git a/CHANGELOG.md b/CHANGELOG.md index ce3904e79a..8664b22e88 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ This section is for maintaining a changelog for all breaking changes for the cli ### Added - Add missed fields to PhraseSuggestOption: collapseMatch ([#940](https://github.com/opensearch-project/opensearch-java/pull/940)) +- Add missed fields to bulk's UpdateOperation: source ([#947](https://github.com/opensearch-project/opensearch-java/pull/947)) ### Dependencies 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 c1fae6cb27..d268708f4c 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 @@ -41,6 +41,7 @@ import org.opensearch.client.json.JsonpSerializer; import org.opensearch.client.json.NdJsonpSerializable; import org.opensearch.client.opensearch._types.Script; +import org.opensearch.client.opensearch.core.search.SourceConfig; import org.opensearch.client.util.ApiTypeHelper; import org.opensearch.client.util.ObjectBuilder; @@ -156,6 +157,9 @@ public static class Builder extends BulkOperationBase.AbstractBuilder @Nullable private Script script; + @Nullable + private SourceConfig source; + /** * API name: {@code document} */ @@ -220,6 +224,21 @@ public final Builder retryOnConflict(@Nullable Integer value) { return this; } + /** + * API name: {@code _source} + */ + public final Builder source(@Nullable SourceConfig value) { + this.source = value; + return this; + } + + /** + * API name: {@code _source} + */ + public final Builder source(Function> fn) { + return this.source(fn.apply(new SourceConfig.Builder()).build()); + } + /** * Serializer for TDocument. If not set, an attempt will be made to find a * serializer from the JSON context. @@ -249,6 +268,7 @@ public UpdateOperation build() { .detectNoop(detectNoop) .script(script) .upsert(upsert) + .source(source) .tDocumentSerializer(tDocumentSerializer) .build(); 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 0caf7cd372..95d0a9f3f4 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 @@ -9,12 +9,14 @@ package org.opensearch.client.opensearch.core.bulk; import jakarta.json.stream.JsonGenerator; +import java.util.function.Function; import javax.annotation.Nullable; import org.opensearch.client.json.JsonpMapper; import org.opensearch.client.json.JsonpSerializable; import org.opensearch.client.json.JsonpSerializer; import org.opensearch.client.json.JsonpUtils; import org.opensearch.client.opensearch._types.Script; +import org.opensearch.client.opensearch.core.search.SourceConfig; import org.opensearch.client.util.ObjectBuilder; public class UpdateOperationData implements JsonpSerializable { @@ -39,6 +41,9 @@ public class UpdateOperationData implements JsonpSerializable { @Nullable private final JsonpSerializer tDocumentSerializer; + @Nullable + private final SourceConfig source; + private UpdateOperationData(Builder builder) { this.document = builder.document; this.docAsUpsert = builder.docAsUpsert; @@ -47,7 +52,7 @@ private UpdateOperationData(Builder builder) { this.script = builder.script; this.upsert = builder.upsert; this.tDocumentSerializer = builder.tDocumentSerializer; - + this.source = builder.source; } @Override @@ -87,6 +92,11 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { generator.writeKey("script"); this.script.serialize(generator, mapper); } + + if (this.source != null) { + generator.writeKey("_source"); + this.source.serialize(generator, mapper); + } } /** @@ -117,6 +127,9 @@ public static class Builder extends BulkOperationBase.AbstractBuilder @Nullable private Script script; + @Nullable + private SourceConfig source; + /** * API name: {@code document} */ @@ -165,6 +178,21 @@ public final Builder script(@Nullable Script value) { return this; } + /** + * API name: {@code _source} + */ + public final Builder source(@Nullable SourceConfig value) { + this.source = value; + return this; + } + + /** + * API name: {@code _source} + */ + public final Builder source(Function> fn) { + return this.source(fn.apply(new SourceConfig.Builder()).build()); + } + /** * Serializer for TDocument. If not set, an attempt will be made to find a * serializer from the JSON context. diff --git a/java-client/src/test/java11/org/opensearch/client/opensearch/integTest/AbstractCrudIT.java b/java-client/src/test/java11/org/opensearch/client/opensearch/integTest/AbstractCrudIT.java index ed6fedc024..f83247fa1b 100644 --- a/java-client/src/test/java11/org/opensearch/client/opensearch/integTest/AbstractCrudIT.java +++ b/java-client/src/test/java11/org/opensearch/client/opensearch/integTest/AbstractCrudIT.java @@ -204,6 +204,7 @@ public void testUpdate() throws Exception { UpdateRequest updateRequest = new UpdateRequest.Builder().index("index") .id("does_not_exist") .doc(appData) + .source(s -> s.fetch(randomBoolean())) .build(); try { javaClient().update(updateRequest, AppData.class);