From 7480de50fd44e1ff527d8bb689ad52654e3e9535 Mon Sep 17 00:00:00 2001 From: kmessaoudi Date: Tue, 19 Mar 2024 16:08:48 +0100 Subject: [PATCH] feat(add-xy_shape): Ability to use xy_shape field type (#885) * feat(add-xy_shape): Ability to use xy_shape field type Signed-off-by: MESSAOUDI Khadidja * update changelog Signed-off-by: MESSAOUDI Khadidja * Fix changelog and add license header Signed-off-by: MESSAOUDI Khadidja * updated license header Signed-off-by: MESSAOUDI Khadidja * remove shape property Signed-off-by: MESSAOUDI Khadidja * fix test after removing shape Signed-off-by: MESSAOUDI Khadidja * adapt ShapeQuery test to XyShapeQuery Signed-off-by: MESSAOUDI Khadidja * Add ES license headers Signed-off-by: MESSAOUDI Khadidja * Add ES license headers on tests Signed-off-by: MESSAOUDI Khadidja --------- Signed-off-by: MESSAOUDI Khadidja (cherry picked from commit ccdb56a31dca1184b29b3948ee66835df5681dd0) --- CHANGELOG.md | 4 +- .../opensearch/_types/mapping/FieldType.java | 2 +- .../opensearch/_types/mapping/Property.java | 26 +++---- .../_types/mapping/PropertyBuilders.java | 6 +- ...hapeProperty.java => XyShapeProperty.java} | 58 +++++++------- .../opensearch/_types/query_dsl/Query.java | 27 ++----- .../_types/query_dsl/QueryBuilders.java | 6 +- ...FieldQuery.java => XyShapeFieldQuery.java} | 76 +++++++++---------- .../{ShapeQuery.java => XyShapeQuery.java} | 67 ++++++++-------- .../client/opensearch/ingest/ShapeType.java | 2 +- .../_types/query_dsl/ShapeFieldQueryTest.java | 15 ---- .../_types/query_dsl/ShapeQueryTest.java | 17 ----- .../query_dsl/XyShapeFieldQueryTest.java | 46 +++++++++++ .../_types/query_dsl/XyShapeQueryTest.java | 49 ++++++++++++ .../opensearch/model/BehaviorsTest.java | 8 +- 15 files changed, 228 insertions(+), 181 deletions(-) rename java-client/src/main/java/org/opensearch/client/opensearch/_types/mapping/{ShapeProperty.java => XyShapeProperty.java} (72%) rename java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/{ShapeFieldQuery.java => XyShapeFieldQuery.java} (64%) rename java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/{ShapeQuery.java => XyShapeQuery.java} (65%) delete mode 100644 java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/ShapeFieldQueryTest.java delete mode 100644 java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/ShapeQueryTest.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 6a29cad6c9..4432a28867 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## [Unreleased 2.x] ### Added +- Add xy_shape property ([#884](https://github.com/opensearch-project/opensearch-java/pull/885)) ### Dependencies - Bumps `io.github.classgraph:classgraph` from 4.8.161 to 4.8.165 @@ -15,6 +16,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### Deprecated ### Removed +- Delete shape property ([#884](https://github.com/opensearch-project/opensearch-java/pull/885)) ### Fixed - Fix integer overflow for variables in indices stats response ([#877](https://github.com/opensearch-project/opensearch-java/pull/877)) @@ -322,4 +324,4 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) [2.5.0]: https://github.com/opensearch-project/opensearch-java/compare/v2.4.0...v2.5.0 [2.4.0]: https://github.com/opensearch-project/opensearch-java/compare/v2.3.0...v2.4.0 [2.3.0]: https://github.com/opensearch-project/opensearch-java/compare/v2.2.0...v2.3.0 -[2.2.0]: https://github.com/opensearch-project/opensearch-java/compare/v2.1.0...v2.2.0 \ No newline at end of file +[2.2.0]: https://github.com/opensearch-project/opensearch-java/compare/v2.1.0...v2.2.0 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..d60600a88c 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 @@ -109,7 +109,7 @@ public enum FieldType implements JsonEnum { FlatObject("flat_object"), - Shape("shape"), + XyShape("xy_shape"), Histogram("histogram"), 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..bf4db5c992 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 @@ -136,7 +136,7 @@ public enum Kind implements JsonEnum { SearchAsYouType("search_as_you_type"), - Shape("shape"), + XyShape("xy_shape"), Short("short"), @@ -845,20 +845,20 @@ public SearchAsYouTypeProperty searchAsYouType() { } /** - * Is this variant instance of kind {@code shape}? + * Is this variant instance of kind {@code xy_shape}? */ - public boolean isShape() { - return _kind == Kind.Shape; + public boolean isXyShape() { + return _kind == Kind.XyShape; } /** - * Get the {@code shape} variant value. + * Get the {@code xy_shape} variant value. * * @throws IllegalStateException - * if the current variant is not of the {@code shape} kind. + * if the current variant is not of the {@code xy_shape} kind. */ - public ShapeProperty shape() { - return TaggedUnionUtils.get(this, Kind.Shape); + public XyShapeProperty xyShape() { + return TaggedUnionUtils.get(this, Kind.XyShape); } /** @@ -1364,14 +1364,14 @@ public ObjectBuilder searchAsYouType( return this.searchAsYouType(fn.apply(new SearchAsYouTypeProperty.Builder()).build()); } - public ObjectBuilder shape(ShapeProperty v) { - this._kind = Kind.Shape; + public ObjectBuilder xyShape(XyShapeProperty v) { + this._kind = Kind.XyShape; this._value = v; return this; } - public ObjectBuilder shape(Function> fn) { - return this.shape(fn.apply(new ShapeProperty.Builder()).build()); + public ObjectBuilder xyShape(Function> fn) { + return this.xyShape(fn.apply(new XyShapeProperty.Builder()).build()); } public ObjectBuilder short_(ShortNumberProperty v) { @@ -1483,7 +1483,7 @@ protected static void setupPropertyDeserializer(ObjectDeserializer op) op.add(Builder::rankFeatures, RankFeaturesProperty._DESERIALIZER, "rank_features"); 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..4afb4b9f2f 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 @@ -332,11 +332,11 @@ public static SearchAsYouTypeProperty.Builder searchAsYouType() { } /** - * Creates a builder for the {@link ShapeProperty shape} {@code Property} + * Creates a builder for the {@link XyShapeProperty xy_shape} {@code Property} * variant. */ - public static ShapeProperty.Builder shape() { - return new ShapeProperty.Builder(); + public static XyShapeProperty.Builder xyShape() { + return new XyShapeProperty.Builder(); } /** diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/mapping/ShapeProperty.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/mapping/XyShapeProperty.java similarity index 72% rename from java-client/src/main/java/org/opensearch/client/opensearch/_types/mapping/ShapeProperty.java rename to java-client/src/main/java/org/opensearch/client/opensearch/_types/mapping/XyShapeProperty.java index 46df0cefad..3622ef09e4 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/mapping/ShapeProperty.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/mapping/XyShapeProperty.java @@ -32,6 +32,8 @@ 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; @@ -42,16 +44,14 @@ import org.opensearch.client.json.ObjectDeserializer; import org.opensearch.client.util.ObjectBuilder; -// typedef: _types.mapping.ShapeProperty - /** - * The shape data type facilitates the indexing of and searching + * The xy_shape data type facilitates the indexing of and searching * with arbitrary x, y cartesian shapes such as rectangles and * polygons. * */ @JsonpDeserializable -public class ShapeProperty extends DocValuesPropertyBase implements PropertyVariant { +public class XyShapeProperty extends DocValuesPropertyBase implements PropertyVariant { @Nullable private final Boolean coerce; @@ -66,7 +66,7 @@ public class ShapeProperty extends DocValuesPropertyBase implements PropertyVari // --------------------------------------------------------------------------------------------- - private ShapeProperty(Builder builder) { + private XyShapeProperty(XyShapeProperty.Builder builder) { super(builder); this.coerce = builder.coerce; @@ -76,8 +76,8 @@ private ShapeProperty(Builder builder) { } - public static ShapeProperty of(Function> fn) { - return fn.apply(new Builder()).build(); + public static XyShapeProperty of(Function> fn) { + return fn.apply(new XyShapeProperty.Builder()).build(); } /** @@ -85,7 +85,7 @@ public static ShapeProperty of(Function> f */ @Override public Property.Kind _propertyKind() { - return Property.Kind.Shape; + return Property.Kind.XyShape; } /** @@ -122,7 +122,7 @@ public final GeoOrientation orientation() { protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { - generator.write("type", "shape"); + generator.write("type", "xy_shape"); super.serializeInternal(generator, mapper); if (this.coerce != null) { generator.writeKey("coerce"); @@ -149,10 +149,12 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { // --------------------------------------------------------------------------------------------- /** - * Builder for {@link ShapeProperty}. + * Builder for {@link XyShapeProperty}. */ - public static class Builder extends DocValuesPropertyBase.AbstractBuilder implements ObjectBuilder { + public static class Builder extends DocValuesPropertyBase.AbstractBuilder + implements + ObjectBuilder { @Nullable private Boolean coerce; @@ -168,7 +170,7 @@ public static class Builder extends DocValuesPropertyBase.AbstractBuilder _DESERIALIZER = ObjectBuilderDeserializer.lazy( - Builder::new, - ShapeProperty::setupShapePropertyDeserializer + public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( + XyShapeProperty.Builder::new, + XyShapeProperty::setupXyShapePropertyDeserializer ); - protected static void setupShapePropertyDeserializer(ObjectDeserializer op) { + protected static void setupXyShapePropertyDeserializer(ObjectDeserializer op) { DocValuesPropertyBase.setupDocValuesPropertyBaseDeserializer(op); - op.add(Builder::coerce, JsonpDeserializer.booleanDeserializer(), "coerce"); - op.add(Builder::ignoreMalformed, JsonpDeserializer.booleanDeserializer(), "ignore_malformed"); - op.add(Builder::ignoreZValue, JsonpDeserializer.booleanDeserializer(), "ignore_z_value"); - op.add(Builder::orientation, GeoOrientation._DESERIALIZER, "orientation"); + 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..000fdc663d 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 @@ -142,7 +142,7 @@ public enum Kind implements JsonEnum { ScriptScore("script_score"), - Shape("shape"), + XyShape("xy_shape"), SimpleQueryString("simple_query_string"), @@ -915,20 +915,20 @@ public ScriptScoreQuery scriptScore() { } /** - * Is this variant instance of kind {@code shape}? + * Is this variant instance of kind {@code xy_shape}? */ - public boolean isShape() { - return _kind == Kind.Shape; + public boolean isXyShape() { + return _kind == Kind.XyShape; } /** - * Get the {@code shape} variant value. + * Get the {@code xy_shape} variant value. * * @throws IllegalStateException - * if the current variant is not of the {@code shape} kind. + * if the current variant is not of the {@code xy_shape} kind. */ - public ShapeQuery shape() { - return TaggedUnionUtils.get(this, Kind.Shape); + public XyShapeQuery xyShape() { + return TaggedUnionUtils.get(this, Kind.XyShape); } /** @@ -1639,16 +1639,6 @@ public ObjectBuilder scriptScore(Function shape(ShapeQuery v) { - this._kind = Kind.Shape; - this._value = v; - return this; - } - - public ObjectBuilder shape(Function> fn) { - return this.shape(fn.apply(new ShapeQuery.Builder()).build()); - } - public ObjectBuilder simpleQueryString(SimpleQueryStringQuery v) { this._kind = Kind.SimpleQueryString; this._value = v; @@ -1858,7 +1848,6 @@ protected static void setupQueryDeserializer(ObjectDeserializer op) { op.add(Builder::regexp, RegexpQuery._DESERIALIZER, "regexp"); op.add(Builder::script, ScriptQuery._DESERIALIZER, "script"); op.add(Builder::scriptScore, ScriptScoreQuery._DESERIALIZER, "script_score"); - op.add(Builder::shape, ShapeQuery._DESERIALIZER, "shape"); op.add(Builder::simpleQueryString, SimpleQueryStringQuery._DESERIALIZER, "simple_query_string"); op.add(Builder::spanContaining, SpanContainingQuery._DESERIALIZER, "span_containing"); op.add(Builder::fieldMaskingSpan, SpanFieldMaskingQuery._DESERIALIZER, "field_masking_span"); 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..f39900a0fc 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 @@ -344,10 +344,10 @@ public static ScriptScoreQuery.Builder scriptScore() { } /** - * Creates a builder for the {@link ShapeQuery shape} {@code Query} variant. + * Creates a builder for the {@link XyShapeQuery xy_shape} {@code Query} variant. */ - public static ShapeQuery.Builder shape() { - return new ShapeQuery.Builder(); + public static XyShapeQuery.Builder xyShape() { + return new XyShapeQuery.Builder(); } /** diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/ShapeFieldQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/XyShapeFieldQuery.java similarity index 64% rename from java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/ShapeFieldQuery.java rename to java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/XyShapeFieldQuery.java index 53a4771a58..cca95afd6e 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/ShapeFieldQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/XyShapeFieldQuery.java @@ -35,21 +35,13 @@ import jakarta.json.stream.JsonGenerator; import java.util.function.Function; import javax.annotation.Nullable; -import org.opensearch.client.json.JsonData; -import org.opensearch.client.json.JsonpDeserializable; -import org.opensearch.client.json.JsonpDeserializer; -import org.opensearch.client.json.JsonpMapper; -import org.opensearch.client.json.JsonpSerializable; -import org.opensearch.client.json.ObjectBuilderDeserializer; -import org.opensearch.client.json.ObjectDeserializer; +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.ShapeFieldQuery - -@JsonpDeserializable -public class ShapeFieldQuery implements JsonpSerializable { +// typedef: _types.query_dsl.XyShapeFieldQuery +public class XyShapeFieldQuery implements JsonpSerializable { @Nullable private final FieldLookup indexedShape; @@ -57,20 +49,20 @@ public class ShapeFieldQuery implements JsonpSerializable { private final GeoShapeRelation relation; @Nullable - private final JsonData shape; + private final JsonData xyShape; // --------------------------------------------------------------------------------------------- - private ShapeFieldQuery(Builder builder) { + private XyShapeFieldQuery(XyShapeFieldQuery.Builder builder) { this.indexedShape = builder.indexedShape; this.relation = builder.relation; - this.shape = builder.shape; + this.xyShape = builder.xyShape; } - public static ShapeFieldQuery of(Function> fn) { - return fn.apply(new Builder()).build(); + public static XyShapeFieldQuery of(Function> fn) { + return fn.apply(new XyShapeFieldQuery.Builder()).build(); } /** @@ -93,8 +85,8 @@ public final GeoShapeRelation relation() { * API name: {@code shape} */ @Nullable - public final JsonData shape() { - return this.shape; + public final JsonData xyShape() { + return this.xyShape; } /** @@ -117,23 +109,23 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { generator.writeKey("relation"); this.relation.serialize(generator, mapper); } - if (this.shape != null) { - generator.writeKey("shape"); - this.shape.serialize(generator, mapper); + if (this.xyShape != null) { + generator.writeKey("xy_shape"); + this.xyShape.serialize(generator, mapper); } } - public Builder toBuilder() { - return new Builder().indexedShape(indexedShape).relation(relation).shape(shape); + public XyShapeFieldQuery.Builder toBuilder() { + return new XyShapeFieldQuery.Builder().indexedShape(indexedShape).relation(relation).xyShape(xyShape); } // --------------------------------------------------------------------------------------------- /** - * Builder for {@link ShapeFieldQuery}. + * Builder for {@link XyShapeFieldQuery}. */ - public static class Builder extends ObjectBuilderBase implements ObjectBuilder { + public static class Builder extends ObjectBuilderBase implements ObjectBuilder { @Nullable private FieldLookup indexedShape; @@ -141,12 +133,12 @@ public static class Builder extends ObjectBuilderBase implements ObjectBuilder> fn) { + public final XyShapeFieldQuery.Builder indexedShape(Function> fn) { return this.indexedShape(fn.apply(new FieldLookup.Builder()).build()); } /** * API name: {@code relation} */ - public final Builder relation(@Nullable GeoShapeRelation value) { + public final XyShapeFieldQuery.Builder relation(@Nullable GeoShapeRelation value) { this.relation = value; return this; } @@ -169,39 +161,39 @@ public final Builder relation(@Nullable GeoShapeRelation value) { /** * API name: {@code shape} */ - public final Builder shape(@Nullable JsonData value) { - this.shape = value; + public final XyShapeFieldQuery.Builder xyShape(@Nullable JsonData value) { + this.xyShape = value; return this; } /** - * Builds a {@link ShapeFieldQuery}. + * Builds a {@link XyShapeFieldQuery}. * * @throws NullPointerException * if some of the required fields are null. */ - public ShapeFieldQuery build() { + public XyShapeFieldQuery build() { _checkSingleUse(); - return new ShapeFieldQuery(this); + return new XyShapeFieldQuery(this); } } // --------------------------------------------------------------------------------------------- /** - * Json deserializer for {@link ShapeFieldQuery} + * Json deserializer for {@link XyShapeFieldQuery} */ - public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( - Builder::new, - ShapeFieldQuery::setupShapeFieldQueryDeserializer + public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( + XyShapeFieldQuery.Builder::new, + XyShapeFieldQuery::setupXyShapeFieldQueryDeserializer ); - protected static void setupShapeFieldQueryDeserializer(ObjectDeserializer op) { + protected static void setupXyShapeFieldQueryDeserializer(ObjectDeserializer op) { - op.add(Builder::indexedShape, FieldLookup._DESERIALIZER, "indexed_shape"); - op.add(Builder::relation, GeoShapeRelation._DESERIALIZER, "relation"); - op.add(Builder::shape, JsonData._DESERIALIZER, "shape"); + 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/ShapeQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/XyShapeQuery.java similarity index 65% rename from java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/ShapeQuery.java rename to java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/XyShapeQuery.java index 019387c174..279b59563f 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/ShapeQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/XyShapeQuery.java @@ -43,30 +43,29 @@ import org.opensearch.client.util.ApiTypeHelper; import org.opensearch.client.util.ObjectBuilder; -// typedef: _types.query_dsl.ShapeQuery - +// typedef: _types.query_dsl.XyShapeQuery @JsonpDeserializable -public class ShapeQuery extends QueryBase implements QueryVariant { +public class XyShapeQuery extends QueryBase implements QueryVariant { private final String field; - private final ShapeFieldQuery shape; + private final XyShapeFieldQuery xyShape; @Nullable private final Boolean ignoreUnmapped; // --------------------------------------------------------------------------------------------- - private ShapeQuery(Builder builder) { + private XyShapeQuery(XyShapeQuery.Builder builder) { super(builder); this.field = ApiTypeHelper.requireNonNull(builder.field, this, "field"); - this.shape = ApiTypeHelper.requireNonNull(builder.shape, this, "shape"); + this.xyShape = ApiTypeHelper.requireNonNull(builder.xyShape, this, "xy_shape"); this.ignoreUnmapped = builder.ignoreUnmapped; } - public static ShapeQuery of(Function> fn) { - return fn.apply(new Builder()).build(); + public static XyShapeQuery of(Function> fn) { + return fn.apply(new XyShapeQuery.Builder()).build(); } /** @@ -74,7 +73,7 @@ public static ShapeQuery of(Function> fn) { */ @Override public Query.Kind _queryKind() { - return Query.Kind.Shape; + return Query.Kind.XyShape; } /** @@ -87,8 +86,8 @@ public final String field() { /** * Required - */ - public final ShapeFieldQuery shape() { - return this.shape; + public final XyShapeFieldQuery xyShape() { + return this.xyShape; } /** @@ -101,7 +100,7 @@ public final Boolean ignoreUnmapped() { protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { generator.writeKey(this.field); - this.shape.serialize(generator, mapper); + this.xyShape.serialize(generator, mapper); super.serializeInternal(generator, mapper); if (this.ignoreUnmapped != null) { @@ -112,25 +111,25 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } - public Builder toBuilder() { - return new Builder().field(field).shape(shape); + public XyShapeQuery.Builder toBuilder() { + return new XyShapeQuery.Builder().field(field).xyShape(xyShape); } // --------------------------------------------------------------------------------------------- /** - * Builder for {@link ShapeQuery}. + * Builder for {@link XyShapeQuery}. */ - public static class Builder extends QueryBase.AbstractBuilder implements ObjectBuilder { + public static class Builder extends QueryBase.AbstractBuilder implements ObjectBuilder { private String field; - private ShapeFieldQuery shape; + private XyShapeFieldQuery xyShape; /** * Required - */ - public final Builder field(String value) { + public final XyShapeQuery.Builder field(String value) { this.field = value; return this; } @@ -138,16 +137,16 @@ public final Builder field(String value) { /** * Required - */ - public final Builder shape(ShapeFieldQuery value) { - this.shape = value; + public final XyShapeQuery.Builder xyShape(XyShapeFieldQuery value) { + this.xyShape = value; return this; } /** * Required - */ - public final Builder shape(Function> fn) { - return this.shape(fn.apply(new ShapeFieldQuery.Builder()).build()); + public final XyShapeQuery.Builder xyShape(Function> fn) { + return this.xyShape(fn.apply(new XyShapeFieldQuery.Builder()).build()); } @Nullable @@ -156,46 +155,46 @@ public final Builder shape(Function _DESERIALIZER = ObjectBuilderDeserializer.lazy( - Builder::new, - ShapeQuery::setupShapeQueryDeserializer + public static final JsonpDeserializer _DESERIALIZER = ObjectBuilderDeserializer.lazy( + XyShapeQuery.Builder::new, + XyShapeQuery::setupXyShapeQueryDeserializer ); - protected static void setupShapeQueryDeserializer(ObjectDeserializer op) { + protected static void setupXyShapeQueryDeserializer(ObjectDeserializer op) { QueryBase.setupQueryBaseDeserializer(op); - op.add(Builder::ignoreUnmapped, JsonpDeserializer.booleanDeserializer(), "ignore_unmapped"); + op.add(XyShapeQuery.Builder::ignoreUnmapped, JsonpDeserializer.booleanDeserializer(), "ignore_unmapped"); op.setUnknownFieldHandler((builder, name, parser, mapper) -> { builder.field(name); - builder.shape(ShapeFieldQuery._DESERIALIZER.deserialize(parser, mapper)); + 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..5e6b30fd68 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 @@ -39,7 +39,7 @@ public enum ShapeType implements JsonEnum { GeoShape("geo_shape"), - Shape("shape"), + XyShape("xy_shape"), ; diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/ShapeFieldQueryTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/ShapeFieldQueryTest.java deleted file mode 100644 index 9d80ad39d6..0000000000 --- a/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/ShapeFieldQueryTest.java +++ /dev/null @@ -1,15 +0,0 @@ -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 ShapeFieldQueryTest extends ModelTestCase { - @Test - public void toBuilder() { - ShapeFieldQuery origin = new ShapeFieldQuery.Builder().shape(JsonData.of("{}")).build(); - ShapeFieldQuery copied = origin.toBuilder().build(); - - assertEquals(toJson(copied), toJson(origin)); - } -} diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/ShapeQueryTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/ShapeQueryTest.java deleted file mode 100644 index c6de52792d..0000000000 --- a/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/ShapeQueryTest.java +++ /dev/null @@ -1,17 +0,0 @@ -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 ShapeQueryTest extends ModelTestCase { - @Test - public void toBuilder() { - ShapeQuery origin = new ShapeQuery.Builder().field("field") - .shape(new ShapeFieldQuery.Builder().shape(JsonData.of("{}")).build()) - .build(); - ShapeQuery copied = origin.toBuilder().build(); - - assertEquals(toJson(copied), toJson(origin)); - } -} 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..daeee9e2e1 --- /dev/null +++ b/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/XyShapeFieldQueryTest.java @@ -0,0 +1,46 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +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..3be37905ac --- /dev/null +++ b/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/XyShapeQueryTest.java @@ -0,0 +1,49 @@ +/* + * SPDX-License-Identifier: Apache-2.0 + * + * The OpenSearch Contributors require contributions made to + * this file be licensed under the Apache-2.0 license or a + * compatible open source license. + */ + +/* + * Licensed to Elasticsearch B.V. under one or more contributor + * license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright + * ownership. Elasticsearch B.V. licenses this file to you under + * the Apache License, Version 2.0 (the "License"); you may + * not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/* + * Modifications Copyright OpenSearch Contributors. See + * GitHub history for details. + */ + +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)); + } +} diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/model/BehaviorsTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/model/BehaviorsTest.java index 02f6058af3..cd10c73915 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/model/BehaviorsTest.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/model/BehaviorsTest.java @@ -42,9 +42,9 @@ import org.opensearch.client.opensearch._types.SortOptionsBuilders; import org.opensearch.client.opensearch._types.SortOrder; import org.opensearch.client.opensearch._types.query_dsl.Query; -import org.opensearch.client.opensearch._types.query_dsl.ShapeQuery; import org.opensearch.client.opensearch._types.query_dsl.TermQuery; import org.opensearch.client.opensearch._types.query_dsl.WrapperQuery; +import org.opensearch.client.opensearch._types.query_dsl.XyShapeQuery; import org.opensearch.client.util.MapBuilder; public class BehaviorsTest extends ModelTestCase { @@ -62,9 +62,9 @@ public void testSingleKeyDictionary() { @Test public void testAdditionalPropertyOnClass() { - ShapeQuery q = new ShapeQuery.Builder().queryName("query-name") + XyShapeQuery q = new XyShapeQuery.Builder().queryName("query-name") .field("field-name") - .shape(_0 -> _0.relation(GeoShapeRelation.Disjoint)) + .xyShape(_0 -> _0.relation(GeoShapeRelation.Disjoint)) .ignoreUnmapped(true) .build(); @@ -72,7 +72,7 @@ public void testAdditionalPropertyOnClass() { assertEquals("query-name", q.queryName()); assertTrue(q.ignoreUnmapped()); - assertEquals(GeoShapeRelation.Disjoint, q.shape().relation()); + assertEquals(GeoShapeRelation.Disjoint, q.xyShape().relation()); System.out.println(toJson(q)); }