Skip to content

Commit 85775ac

Browse files
Add missed fields to bulk's UpdateOperation: source (#947) (#948)
(cherry picked from commit a6c7dc9) Signed-off-by: Andriy Redko <[email protected]> Signed-off-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 909a5db commit 85775ac

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
44
## [Unreleased 2.x]
55
### Added
66
- Add missed fields to PhraseSuggestOption: collapseMatch ([#940](https://github.com/opensearch-project/opensearch-java/pull/940))
7+
- Add missed fields to bulk's UpdateOperation: source ([#947](https://github.com/opensearch-project/opensearch-java/pull/947))
78

89
### Dependencies
910
- Bumps `com.github.jk1.dependency-license-report` from 2.6 to 2.7

java-client/src/main/java/org/opensearch/client/opensearch/core/bulk/UpdateOperation.java

+20
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
import org.opensearch.client.json.JsonpSerializer;
4242
import org.opensearch.client.json.NdJsonpSerializable;
4343
import org.opensearch.client.opensearch._types.Script;
44+
import org.opensearch.client.opensearch.core.search.SourceConfig;
4445
import org.opensearch.client.util.ApiTypeHelper;
4546
import org.opensearch.client.util.ObjectBuilder;
4647

@@ -156,6 +157,9 @@ public static class Builder<TDocument> extends BulkOperationBase.AbstractBuilder
156157
@Nullable
157158
private Script script;
158159

160+
@Nullable
161+
private SourceConfig source;
162+
159163
/**
160164
* API name: {@code document}
161165
*/
@@ -220,6 +224,21 @@ public final Builder<TDocument> retryOnConflict(@Nullable Integer value) {
220224
return this;
221225
}
222226

227+
/**
228+
* API name: {@code _source}
229+
*/
230+
public final Builder<TDocument> source(@Nullable SourceConfig value) {
231+
this.source = value;
232+
return this;
233+
}
234+
235+
/**
236+
* API name: {@code _source}
237+
*/
238+
public final Builder<TDocument> source(Function<SourceConfig.Builder, ObjectBuilder<SourceConfig>> fn) {
239+
return this.source(fn.apply(new SourceConfig.Builder()).build());
240+
}
241+
223242
/**
224243
* Serializer for TDocument. If not set, an attempt will be made to find a
225244
* serializer from the JSON context.
@@ -249,6 +268,7 @@ public UpdateOperation<TDocument> build() {
249268
.detectNoop(detectNoop)
250269
.script(script)
251270
.upsert(upsert)
271+
.source(source)
252272
.tDocumentSerializer(tDocumentSerializer)
253273
.build();
254274

java-client/src/main/java/org/opensearch/client/opensearch/core/bulk/UpdateOperationData.java

+29-1
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,14 @@
99
package org.opensearch.client.opensearch.core.bulk;
1010

1111
import jakarta.json.stream.JsonGenerator;
12+
import java.util.function.Function;
1213
import javax.annotation.Nullable;
1314
import org.opensearch.client.json.JsonpMapper;
1415
import org.opensearch.client.json.JsonpSerializable;
1516
import org.opensearch.client.json.JsonpSerializer;
1617
import org.opensearch.client.json.JsonpUtils;
1718
import org.opensearch.client.opensearch._types.Script;
19+
import org.opensearch.client.opensearch.core.search.SourceConfig;
1820
import org.opensearch.client.util.ObjectBuilder;
1921

2022
public class UpdateOperationData<TDocument> implements JsonpSerializable {
@@ -39,6 +41,9 @@ public class UpdateOperationData<TDocument> implements JsonpSerializable {
3941
@Nullable
4042
private final JsonpSerializer<TDocument> tDocumentSerializer;
4143

44+
@Nullable
45+
private final SourceConfig source;
46+
4247
private UpdateOperationData(Builder<TDocument> builder) {
4348
this.document = builder.document;
4449
this.docAsUpsert = builder.docAsUpsert;
@@ -47,7 +52,7 @@ private UpdateOperationData(Builder<TDocument> builder) {
4752
this.script = builder.script;
4853
this.upsert = builder.upsert;
4954
this.tDocumentSerializer = builder.tDocumentSerializer;
50-
55+
this.source = builder.source;
5156
}
5257

5358
@Override
@@ -87,6 +92,11 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
8792
generator.writeKey("script");
8893
this.script.serialize(generator, mapper);
8994
}
95+
96+
if (this.source != null) {
97+
generator.writeKey("_source");
98+
this.source.serialize(generator, mapper);
99+
}
90100
}
91101

92102
/**
@@ -117,6 +127,9 @@ public static class Builder<TDocument> extends BulkOperationBase.AbstractBuilder
117127
@Nullable
118128
private Script script;
119129

130+
@Nullable
131+
private SourceConfig source;
132+
120133
/**
121134
* API name: {@code document}
122135
*/
@@ -165,6 +178,21 @@ public final Builder<TDocument> script(@Nullable Script value) {
165178
return this;
166179
}
167180

181+
/**
182+
* API name: {@code _source}
183+
*/
184+
public final Builder<TDocument> source(@Nullable SourceConfig value) {
185+
this.source = value;
186+
return this;
187+
}
188+
189+
/**
190+
* API name: {@code _source}
191+
*/
192+
public final Builder<TDocument> source(Function<SourceConfig.Builder, ObjectBuilder<SourceConfig>> fn) {
193+
return this.source(fn.apply(new SourceConfig.Builder()).build());
194+
}
195+
168196
/**
169197
* Serializer for TDocument. If not set, an attempt will be made to find a
170198
* serializer from the JSON context.

java-client/src/test/java11/org/opensearch/client/opensearch/integTest/AbstractCrudIT.java

+1
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ public void testUpdate() throws Exception {
204204
UpdateRequest<AppData, AppData> updateRequest = new UpdateRequest.Builder<AppData, AppData>().index("index")
205205
.id("does_not_exist")
206206
.doc(appData)
207+
.source(s -> s.fetch(randomBoolean()))
207208
.build();
208209
try {
209210
javaClient().update(updateRequest, AppData.class);

0 commit comments

Comments
 (0)