Skip to content

Commit

Permalink
Added detectNoop option to UpdateOperation (opensearch-project#744)
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Winkler <[email protected]>
  • Loading branch information
fs-chris committed Nov 29, 2023
1 parent f80d1e3 commit ee734ff
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ public static class Builder<TDocument> extends BulkOperationBase.AbstractBuilder
@Nullable
private Boolean scriptedUpsert;

@Nullable
private Boolean detectNoop;

@Nullable
private TDocument upsert;

Expand Down Expand Up @@ -182,6 +185,14 @@ public final Builder<TDocument> scriptedUpsert(@Nullable Boolean value) {
return this;
}

/**
* API name: {@code detect_noop}
*/
public final Builder<TDocument> detectNoop(@Nullable Boolean value) {
this.detectNoop = value;
return this;
}

/**
* API name: {@code upsert}
*/
Expand Down Expand Up @@ -241,6 +252,7 @@ public UpdateOperation<TDocument> build() {
data = new UpdateOperationData.Builder<TDocument>().document(document)
.docAsUpsert(docAsUpsert)
.scriptedUpsert(scriptedUpsert)
.detectNoop(detectNoop)
.script(script)
.upsert(upsert)
.tDocumentSerializer(tDocumentSerializer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,17 @@

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;
import org.opensearch.client.json.JsonpUtils;
import org.opensearch.client.opensearch._types.Script;
import org.opensearch.client.util.ObjectBuilder;

import jakarta.json.stream.JsonGenerator;

public class UpdateOperationData<TDocument> implements JsonpSerializable {
@Nullable
private final TDocument document;
Expand All @@ -27,6 +29,9 @@ public class UpdateOperationData<TDocument> implements JsonpSerializable {
@Nullable
private final Boolean scriptedUpsert;

@Nullable
private final Boolean detectNoop;

@Nullable
private final TDocument upsert;

Expand All @@ -40,6 +45,7 @@ private UpdateOperationData(Builder<TDocument> 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;
Expand All @@ -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);
Expand All @@ -85,7 +96,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) {
*/
public static class Builder<TDocument> extends BulkOperationBase.AbstractBuilder<Builder<TDocument>>
implements
ObjectBuilder<UpdateOperationData<TDocument>> {
ObjectBuilder<UpdateOperationData<TDocument>> {

@Nullable
private TDocument document;
Expand All @@ -99,6 +110,9 @@ public static class Builder<TDocument> extends BulkOperationBase.AbstractBuilder
@Nullable
private Boolean scriptedUpsert;

@Nullable
private Boolean detectNoop;

@Nullable
private TDocument upsert;

Expand Down Expand Up @@ -128,7 +142,15 @@ public final Builder<TDocument> scriptedUpsert(@Nullable Boolean value) {
this.scriptedUpsert = value;
return this;
}


/**
* API name: {@code detect_noop}
*/
public final Builder<TDocument> detectNoop(@Nullable Boolean value) {
this.detectNoop = value;
return this;
}

/**
* API name: {@code upsert}
*/
Expand Down Expand Up @@ -165,10 +187,11 @@ protected Builder<TDocument> self() {
* @throws NullPointerException
* if some of the required fields are null.
*/
@Override
public UpdateOperationData<TDocument> build() {
_checkSingleUse();

return new UpdateOperationData<TDocument>(this);
return new UpdateOperationData<>(this);
}
}
}

0 comments on commit ee734ff

Please sign in to comment.