From d4a64ac6e10f3d138379ef0a3b7ca601e71511da Mon Sep 17 00:00:00 2001 From: MESSAOUDI Khadidja Date: Thu, 7 Mar 2024 09:53:25 +0100 Subject: [PATCH] feat(add-xy_shape): Ability to use xy_shape field type Signed-off-by: MESSAOUDI Khadidja --- CHANGELOG.md | 1 + .../opensearch/_types/mapping/FieldType.java | 2 + .../opensearch/_types/mapping/Property.java | 30 +++ .../_types/mapping/PropertyBuilders.java | 8 + .../_types/mapping/XyShapeProperty.java | 206 ++++++++++++++++++ .../opensearch/_types/query_dsl/Query.java | 19 ++ .../_types/query_dsl/QueryBuilders.java | 7 + .../_types/query_dsl/XyShapeFieldQuery.java | 168 ++++++++++++++ .../_types/query_dsl/XyShapeQuery.java | 168 ++++++++++++++ .../client/opensearch/ingest/ShapeType.java | 2 + .../query_dsl/XyShapeFieldQueryTest.java | 14 ++ .../_types/query_dsl/XyShapeQueryTest.java | 17 ++ 12 files changed, 642 insertions(+) create mode 100644 java-client/src/main/java/org/opensearch/client/opensearch/_types/mapping/XyShapeProperty.java create mode 100644 java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/XyShapeFieldQuery.java create mode 100644 java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/XyShapeQuery.java create mode 100644 java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/XyShapeFieldQueryTest.java create mode 100644 java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/XyShapeQueryTest.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b339212a1..c08a96fdeb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ This section is for maintaining a changelog for all breaking changes for the cli ### Added - Document HTTP/2 support ([#330](https://github.com/opensearch-project/opensearch-java/pull/330)) +- Add xy_shape property ([#884](https://github.com/opensearch-project/opensearch-java/pull/885)) ### Dependencies diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/mapping/FieldType.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/mapping/FieldType.java index d2824ee1ee..d5f9c78ea0 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/mapping/FieldType.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/mapping/FieldType.java @@ -111,6 +111,8 @@ public enum FieldType implements JsonEnum { Shape("shape"), + XyShape("xy_shape"), + Histogram("histogram"), ConstantKeyword("constant_keyword"), diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/mapping/Property.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/mapping/Property.java index 2634a090f4..aae7a5bd77 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/mapping/Property.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/mapping/Property.java @@ -138,6 +138,8 @@ public enum Kind implements JsonEnum { Shape("shape"), + XyShape("xy_shape"), + Short("short"), Text("text"), @@ -861,6 +863,23 @@ public ShapeProperty shape() { return TaggedUnionUtils.get(this, Kind.Shape); } + /** + * Is this variant instance of kind {@code xy_shape}? + */ + public boolean isXyShape() { + return _kind == Kind.XyShape; + } + + /** + * Get the {@code xy_shape} variant value. + * + * @throws IllegalStateException + * if the current variant is not of the {@code shape} kind. + */ + public XyShapeProperty xyShape() { + return TaggedUnionUtils.get(this, Kind.XyShape); + } + /** * Is this variant instance of kind {@code short}? */ @@ -1374,6 +1393,16 @@ public ObjectBuilder shape(Function xyShape(XyShapeProperty v) { + this._kind = Kind.XyShape; + this._value = v; + return this; + } + + public ObjectBuilder xyShape(Function> fn) { + return this.xyShape(fn.apply(new XyShapeProperty.Builder()).build()); + } + public ObjectBuilder short_(ShortNumberProperty v) { this._kind = Kind.Short; this._value = v; @@ -1484,6 +1513,7 @@ protected static void setupPropertyDeserializer(ObjectDeserializer op) op.add(Builder::scaledFloat, ScaledFloatNumberProperty._DESERIALIZER, "scaled_float"); op.add(Builder::searchAsYouType, SearchAsYouTypeProperty._DESERIALIZER, "search_as_you_type"); op.add(Builder::shape, ShapeProperty._DESERIALIZER, "shape"); + op.add(Builder::xyShape, XyShapeProperty._DESERIALIZER, "xy_shape"); op.add(Builder::short_, ShortNumberProperty._DESERIALIZER, "short"); op.add(Builder::text, TextProperty._DESERIALIZER, "text"); op.add(Builder::tokenCount, TokenCountProperty._DESERIALIZER, "token_count"); diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/mapping/PropertyBuilders.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/mapping/PropertyBuilders.java index ae7f542eca..e1bc53e93e 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/mapping/PropertyBuilders.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/mapping/PropertyBuilders.java @@ -339,6 +339,14 @@ public static ShapeProperty.Builder shape() { return new ShapeProperty.Builder(); } + /** + * Creates a builder for the {@link XyShapeProperty xy_shape} {@code Property} + * variant. + */ + public static XyShapeProperty.Builder xyShape() { + return new XyShapeProperty.Builder(); + } + /** * Creates a builder for the {@link ShortNumberProperty short} {@code Property} * variant. diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/mapping/XyShapeProperty.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/mapping/XyShapeProperty.java new file mode 100644 index 0000000000..1c5df1eadb --- /dev/null +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/mapping/XyShapeProperty.java @@ -0,0 +1,206 @@ +package org.opensearch.client.opensearch._types.mapping; + +// typedef: _types.mapping.XyShapeProperty + +import jakarta.json.stream.JsonGenerator; +import java.util.function.Function; +import javax.annotation.Nullable; +import org.opensearch.client.json.JsonpDeserializer; +import org.opensearch.client.json.JsonpMapper; +import org.opensearch.client.json.ObjectBuilderDeserializer; +import org.opensearch.client.json.ObjectDeserializer; +import org.opensearch.client.util.ObjectBuilder; + +/** + * The xy_shape data type facilitates the indexing of and searching + * with arbitrary x, y cartesian shapes such as rectangles and + * polygons. + * + */ +public class XyShapeProperty extends DocValuesPropertyBase implements PropertyVariant { + @Nullable + private final Boolean coerce; + + @Nullable + private final Boolean ignoreMalformed; + + @Nullable + private final Boolean ignoreZValue; + + @Nullable + private final GeoOrientation orientation; + + // --------------------------------------------------------------------------------------------- + + private XyShapeProperty(XyShapeProperty.Builder builder) { + super(builder); + + this.coerce = builder.coerce; + this.ignoreMalformed = builder.ignoreMalformed; + this.ignoreZValue = builder.ignoreZValue; + this.orientation = builder.orientation; + + } + + public static XyShapeProperty of(Function> fn) { + return fn.apply(new XyShapeProperty.Builder()).build(); + } + + /** + * Property variant kind. + */ + @Override + public Property.Kind _propertyKind() { + return Property.Kind.XyShape; + } + + /** + * API name: {@code coerce} + */ + @Nullable + public final Boolean coerce() { + return this.coerce; + } + + /** + * API name: {@code ignore_malformed} + */ + @Nullable + public final Boolean ignoreMalformed() { + return this.ignoreMalformed; + } + + /** + * API name: {@code ignore_z_value} + */ + @Nullable + public final Boolean ignoreZValue() { + return this.ignoreZValue; + } + + /** + * API name: {@code orientation} + */ + @Nullable + public final GeoOrientation orientation() { + return this.orientation; + } + + protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { + + generator.write("type", "xy_shape"); + super.serializeInternal(generator, mapper); + if (this.coerce != null) { + generator.writeKey("coerce"); + generator.write(this.coerce); + + } + if (this.ignoreMalformed != null) { + generator.writeKey("ignore_malformed"); + generator.write(this.ignoreMalformed); + + } + if (this.ignoreZValue != null) { + generator.writeKey("ignore_z_value"); + generator.write(this.ignoreZValue); + + } + if (this.orientation != null) { + generator.writeKey("orientation"); + this.orientation.serialize(generator, mapper); + } + + } + + // --------------------------------------------------------------------------------------------- + + /** + * Builder for {@link XyShapeProperty}. + */ + + public static class Builder extends DocValuesPropertyBase.AbstractBuilder + implements + ObjectBuilder { + @Nullable + private Boolean coerce; + + @Nullable + private Boolean ignoreMalformed; + + @Nullable + private Boolean ignoreZValue; + + @Nullable + private GeoOrientation orientation; + + /** + * API name: {@code coerce} + */ + public final XyShapeProperty.Builder coerce(@Nullable Boolean value) { + this.coerce = value; + return this; + } + + /** + * API name: {@code ignore_malformed} + */ + public final XyShapeProperty.Builder ignoreMalformed(@Nullable Boolean value) { + this.ignoreMalformed = value; + return this; + } + + /** + * API name: {@code ignore_z_value} + */ + public final XyShapeProperty.Builder ignoreZValue(@Nullable Boolean value) { + this.ignoreZValue = value; + return this; + } + + /** + * API name: {@code orientation} + */ + public final XyShapeProperty.Builder orientation(@Nullable GeoOrientation value) { + this.orientation = value; + return this; + } + + @Override + protected XyShapeProperty.Builder self() { + return this; + } + + /** + * Builds a {@link XyShapeProperty}. + * + * @throws NullPointerException + * if some of the required fields are null. + */ + public XyShapeProperty build() { + _checkSingleUse(); + + return new XyShapeProperty(this); + } + } + + // --------------------------------------------------------------------------------------------- + + /** + * Json deserializer for {@link XyShapeProperty} + */ + public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( + XyShapeProperty.Builder::new, + XyShapeProperty::setupXyShapePropertyDeserializer + ); + + protected static void setupXyShapePropertyDeserializer(ObjectDeserializer op) { + DocValuesPropertyBase.setupDocValuesPropertyBaseDeserializer(op); + op.add(XyShapeProperty.Builder::coerce, JsonpDeserializer.booleanDeserializer(), "coerce"); + op.add(XyShapeProperty.Builder::ignoreMalformed, JsonpDeserializer.booleanDeserializer(), "ignore_malformed"); + op.add(XyShapeProperty.Builder::ignoreZValue, JsonpDeserializer.booleanDeserializer(), "ignore_z_value"); + op.add(XyShapeProperty.Builder::orientation, GeoOrientation._DESERIALIZER, "orientation"); + + op.ignore("type"); + } + +} diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/Query.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/Query.java index 1510a19473..cd0299e234 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/Query.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/Query.java @@ -144,6 +144,8 @@ public enum Kind implements JsonEnum { Shape("shape"), + XyShape("xy_shape"), + SimpleQueryString("simple_query_string"), SpanContaining("span_containing"), @@ -931,6 +933,23 @@ public ShapeQuery shape() { return TaggedUnionUtils.get(this, Kind.Shape); } + /** + * Is this variant instance of kind {@code xy_shape}? + */ + public boolean isXyShape() { + return _kind == Kind.XyShape; + } + + /** + * Get the {@code xy_shape} variant value. + * + * @throws IllegalStateException + * if the current variant is not of the {@code xy_shape} kind. + */ + public XyShapeQuery xyShape() { + return TaggedUnionUtils.get(this, Kind.XyShape); + } + /** * Is this variant instance of kind {@code simple_query_string}? */ diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/QueryBuilders.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/QueryBuilders.java index 8ddf85b1e8..7fbdb2572c 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/QueryBuilders.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/QueryBuilders.java @@ -350,6 +350,13 @@ public static ShapeQuery.Builder shape() { return new ShapeQuery.Builder(); } + /** + * Creates a builder for the {@link XyShapeQuery shape} {@code Query} variant. + */ + public static XyShapeQuery.Builder xyShape() { + return new XyShapeQuery.Builder(); + } + /** * Creates a builder for the {@link SimpleQueryStringQuery simple_query_string} * {@code Query} variant. diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/XyShapeFieldQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/XyShapeFieldQuery.java new file mode 100644 index 0000000000..020b79c115 --- /dev/null +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/XyShapeFieldQuery.java @@ -0,0 +1,168 @@ +package org.opensearch.client.opensearch._types.query_dsl; + +import jakarta.json.stream.JsonGenerator; +import java.util.function.Function; +import javax.annotation.Nullable; +import org.opensearch.client.json.*; +import org.opensearch.client.opensearch._types.GeoShapeRelation; +import org.opensearch.client.util.ObjectBuilder; +import org.opensearch.client.util.ObjectBuilderBase; + +// typedef: _types.query_dsl.XyShapeFieldQuery +public class XyShapeFieldQuery implements JsonpSerializable { + @Nullable + private final FieldLookup indexedShape; + + @Nullable + private final GeoShapeRelation relation; + + @Nullable + private final JsonData xyShape; + + // --------------------------------------------------------------------------------------------- + + private XyShapeFieldQuery(XyShapeFieldQuery.Builder builder) { + + this.indexedShape = builder.indexedShape; + this.relation = builder.relation; + this.xyShape = builder.xyShape; + + } + + public static XyShapeFieldQuery of(Function> fn) { + return fn.apply(new XyShapeFieldQuery.Builder()).build(); + } + + /** + * API name: {@code indexed_shape} + */ + @Nullable + public final FieldLookup indexedShape() { + return this.indexedShape; + } + + /** + * API name: {@code relation} + */ + @Nullable + public final GeoShapeRelation relation() { + return this.relation; + } + + /** + * API name: {@code shape} + */ + @Nullable + public final JsonData xyShape() { + return this.xyShape; + } + + /** + * Serialize this object to JSON. + */ + public void serialize(JsonGenerator generator, JsonpMapper mapper) { + generator.writeStartObject(); + serializeInternal(generator, mapper); + generator.writeEnd(); + } + + protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { + + if (this.indexedShape != null) { + generator.writeKey("indexed_shape"); + this.indexedShape.serialize(generator, mapper); + + } + if (this.relation != null) { + generator.writeKey("relation"); + this.relation.serialize(generator, mapper); + } + if (this.xyShape != null) { + generator.writeKey("xy_shape"); + this.xyShape.serialize(generator, mapper); + } + } + + public XyShapeFieldQuery.Builder toBuilder() { + return new XyShapeFieldQuery.Builder().indexedShape(indexedShape).relation(relation).xyShape(xyShape); + } + + // --------------------------------------------------------------------------------------------- + + /** + * Builder for {@link XyShapeFieldQuery}. + */ + + public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + @Nullable + private FieldLookup indexedShape; + + @Nullable + private GeoShapeRelation relation; + + @Nullable + private JsonData xyShape; + + /** + * API name: {@code indexed_shape} + */ + public final XyShapeFieldQuery.Builder indexedShape(@Nullable FieldLookup value) { + this.indexedShape = value; + return this; + } + + /** + * API name: {@code indexed_shape} + */ + public final XyShapeFieldQuery.Builder indexedShape(Function> fn) { + return this.indexedShape(fn.apply(new FieldLookup.Builder()).build()); + } + + /** + * API name: {@code relation} + */ + public final XyShapeFieldQuery.Builder relation(@Nullable GeoShapeRelation value) { + this.relation = value; + return this; + } + + /** + * API name: {@code shape} + */ + public final XyShapeFieldQuery.Builder xyShape(@Nullable JsonData value) { + this.xyShape = value; + return this; + } + + /** + * Builds a {@link XyShapeFieldQuery}. + * + * @throws NullPointerException + * if some of the required fields are null. + */ + public XyShapeFieldQuery build() { + _checkSingleUse(); + + return new XyShapeFieldQuery(this); + } + } + + // --------------------------------------------------------------------------------------------- + + /** + * Json deserializer for {@link XyShapeFieldQuery} + */ + public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( + XyShapeFieldQuery.Builder::new, + XyShapeFieldQuery::setupXyShapeFieldQueryDeserializer + ); + + protected static void setupXyShapeFieldQueryDeserializer(ObjectDeserializer op) { + + op.add(XyShapeFieldQuery.Builder::indexedShape, FieldLookup._DESERIALIZER, "indexed_shape"); + op.add(XyShapeFieldQuery.Builder::relation, GeoShapeRelation._DESERIALIZER, "relation"); + op.add(XyShapeFieldQuery.Builder::xyShape, JsonData._DESERIALIZER, "xy_shape"); + + } + +} diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/XyShapeQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/XyShapeQuery.java new file mode 100644 index 0000000000..0757addd35 --- /dev/null +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/XyShapeQuery.java @@ -0,0 +1,168 @@ +package org.opensearch.client.opensearch._types.query_dsl; + +import jakarta.json.stream.JsonGenerator; +import java.util.function.Function; +import javax.annotation.Nullable; +import org.opensearch.client.json.JsonpDeserializer; +import org.opensearch.client.json.JsonpMapper; +import org.opensearch.client.json.ObjectBuilderDeserializer; +import org.opensearch.client.json.ObjectDeserializer; +import org.opensearch.client.util.ApiTypeHelper; +import org.opensearch.client.util.ObjectBuilder; + +// typedef: _types.query_dsl.XyShapeQuery +public class XyShapeQuery extends QueryBase implements QueryVariant { + private final String field; + + private final XyShapeFieldQuery xyShape; + + @Nullable + private final Boolean ignoreUnmapped; + + // --------------------------------------------------------------------------------------------- + + private XyShapeQuery(XyShapeQuery.Builder builder) { + super(builder); + this.field = ApiTypeHelper.requireNonNull(builder.field, this, "field"); + this.xyShape = ApiTypeHelper.requireNonNull(builder.xyShape, this, "xy_shape"); + + this.ignoreUnmapped = builder.ignoreUnmapped; + + } + + public static XyShapeQuery of(Function> fn) { + return fn.apply(new XyShapeQuery.Builder()).build(); + } + + /** + * Query variant kind. + */ + @Override + public Query.Kind _queryKind() { + return Query.Kind.XyShape; + } + + /** + * Required - + */ + public final String field() { + return this.field; + } + + /** + * Required - + */ + public final XyShapeFieldQuery xyShape() { + return this.xyShape; + } + + /** + * API name: {@code ignore_unmapped} + */ + @Nullable + public final Boolean ignoreUnmapped() { + return this.ignoreUnmapped; + } + + protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { + generator.writeKey(this.field); + this.xyShape.serialize(generator, mapper); + + super.serializeInternal(generator, mapper); + if (this.ignoreUnmapped != null) { + generator.writeKey("ignore_unmapped"); + generator.write(this.ignoreUnmapped); + + } + + } + + public XyShapeQuery.Builder toBuilder() { + return new XyShapeQuery.Builder().field(field).xyShape(xyShape); + } + + // --------------------------------------------------------------------------------------------- + + /** + * Builder for {@link ShapeQuery}. + */ + + public static class Builder extends QueryBase.AbstractBuilder implements ObjectBuilder { + private String field; + + private XyShapeFieldQuery xyShape; + + /** + * Required - + */ + public final XyShapeQuery.Builder field(String value) { + this.field = value; + return this; + } + + /** + * Required - + */ + public final XyShapeQuery.Builder xyShape(XyShapeFieldQuery value) { + this.xyShape = value; + return this; + } + + /** + * Required - + */ + public final XyShapeQuery.Builder xyShape(Function> fn) { + return this.xyShape(fn.apply(new XyShapeFieldQuery.Builder()).build()); + } + + @Nullable + private Boolean ignoreUnmapped; + + /** + * API name: {@code ignore_unmapped} + */ + public final XyShapeQuery.Builder ignoreUnmapped(@Nullable Boolean value) { + this.ignoreUnmapped = value; + return this; + } + + @Override + protected XyShapeQuery.Builder self() { + return this; + } + + /** + * Builds a {@link ShapeQuery}. + * + * @throws NullPointerException + * if some of the required fields are null. + */ + public XyShapeQuery build() { + _checkSingleUse(); + + return new XyShapeQuery(this); + } + } + + // --------------------------------------------------------------------------------------------- + + /** + * Json deserializer for {@link ShapeQuery} + */ + public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( + XyShapeQuery.Builder::new, + XyShapeQuery::setupXyShapeQueryDeserializer + ); + + protected static void setupXyShapeQueryDeserializer(ObjectDeserializer op) { + QueryBase.setupQueryBaseDeserializer(op); + op.add(XyShapeQuery.Builder::ignoreUnmapped, JsonpDeserializer.booleanDeserializer(), "ignore_unmapped"); + + op.setUnknownFieldHandler((builder, name, parser, mapper) -> { + builder.field(name); + builder.xyShape(XyShapeFieldQuery._DESERIALIZER.deserialize(parser, mapper)); + }); + + } + +} diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/ingest/ShapeType.java b/java-client/src/main/java/org/opensearch/client/opensearch/ingest/ShapeType.java index f953a99d10..bc6530cac0 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/ingest/ShapeType.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/ingest/ShapeType.java @@ -41,6 +41,8 @@ public enum ShapeType implements JsonEnum { Shape("shape"), + XyShape("xy_shape"), + ; private final String jsonValue; diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/XyShapeFieldQueryTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/XyShapeFieldQueryTest.java new file mode 100644 index 0000000000..8c7d353fd7 --- /dev/null +++ b/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/XyShapeFieldQueryTest.java @@ -0,0 +1,14 @@ +package org.opensearch.client.opensearch._types.query_dsl; + +import org.junit.Test; +import org.opensearch.client.opensearch.model.ModelTestCase; + +public class XyShapeFieldQueryTest extends ModelTestCase { + @Test + public void toBuilder() { + XyShapeFieldQuery origin = new XyShapeFieldQuery.Builder().build(); + XyShapeFieldQuery copied = origin.toBuilder().build(); + + assertEquals(toJson(copied), toJson(origin)); + } +} diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/XyShapeQueryTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/XyShapeQueryTest.java new file mode 100644 index 0000000000..650b78b045 --- /dev/null +++ b/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/XyShapeQueryTest.java @@ -0,0 +1,17 @@ +package org.opensearch.client.opensearch._types.query_dsl; + +import org.junit.Test; +import org.opensearch.client.json.JsonData; +import org.opensearch.client.opensearch.model.ModelTestCase; + +public class XyShapeQueryTest extends ModelTestCase { + @Test + public void toBuilder() { + XyShapeQuery origin = new XyShapeQuery.Builder().field("field") + .xyShape(new XyShapeFieldQuery.Builder().xyShape(JsonData.of("{}")).build()) + .build(); + XyShapeQuery copied = origin.toBuilder().build(); + + assertEquals(toJson(copied), toJson(origin)); + } +}