diff --git a/CHANGELOG.md b/CHANGELOG.md index 11621f6a7..5b4fa5d14 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### Fixed - Fix `unitTest` task not running the tests in the `test` source set ([#2074](https://github.com/opensearch-project/opensearch-java/pull/2074)) +- Allow pre-indexed shape queries by making `shape` optional on `GeoShapeQueryField` and `XyShapeQueryField` ([#2011](https://github.com/opensearch-project/opensearch-java/issues/2011)) ## [Unreleased 3.x] ### Added diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/GeoShapeQueryField.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/GeoShapeQueryField.java index dd2e69a45..cc6b31e53 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/GeoShapeQueryField.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/GeoShapeQueryField.java @@ -49,7 +49,6 @@ import org.opensearch.client.json.ObjectDeserializer; import org.opensearch.client.json.PlainJsonSerializable; import org.opensearch.client.opensearch._types.GeoShapeRelation; -import org.opensearch.client.util.ApiTypeHelper; import org.opensearch.client.util.CopyableBuilder; import org.opensearch.client.util.ObjectBuilder; import org.opensearch.client.util.ObjectBuilderBase; @@ -67,7 +66,7 @@ public class GeoShapeQueryField implements PlainJsonSerializable, ToCopyableBuil @Nullable private final GeoShapeRelation relation; - @Nonnull + @Nullable private final GeoShape shape; // --------------------------------------------------------------------------------------------- @@ -75,7 +74,7 @@ public class GeoShapeQueryField implements PlainJsonSerializable, ToCopyableBuil private GeoShapeQueryField(Builder builder) { this.indexedShape = builder.indexedShape; this.relation = builder.relation; - this.shape = ApiTypeHelper.requireNonNull(builder.shape, this, "shape"); + this.shape = builder.shape; } public static GeoShapeQueryField of(Function> fn) { @@ -99,9 +98,9 @@ public final GeoShapeRelation relation() { } /** - * Required - API name: {@code shape} + * API name: {@code shape} */ - @Nonnull + @Nullable public final GeoShape shape() { return this.shape; } @@ -127,8 +126,10 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { this.relation.serialize(generator, mapper); } - generator.writeKey("shape"); - this.shape.serialize(generator, mapper); + if (this.shape != null) { + generator.writeKey("shape"); + this.shape.serialize(generator, mapper); + } } // --------------------------------------------------------------------------------------------- @@ -152,6 +153,7 @@ public static class Builder extends ObjectBuilderBase implements CopyableBuilder private FieldLookup indexedShape; @Nullable private GeoShapeRelation relation; + @Nullable private GeoShape shape; public Builder() {} @@ -201,16 +203,16 @@ public final Builder relation(@Nullable GeoShapeRelation value) { } /** - * Required - API name: {@code shape} + * API name: {@code shape} */ @Nonnull - public final Builder shape(GeoShape value) { + public final Builder shape(@Nullable GeoShape value) { this.shape = value; return this; } /** - * Required - API name: {@code shape} + * API name: {@code shape} */ @Nonnull public final Builder shape(Function> fn) { @@ -252,7 +254,7 @@ public int hashCode() { int result = 17; result = 31 * result + Objects.hashCode(this.indexedShape); result = 31 * result + Objects.hashCode(this.relation); - result = 31 * result + this.shape.hashCode(); + result = 31 * result + Objects.hashCode(this.shape); return result; } @@ -263,6 +265,6 @@ public boolean equals(Object o) { GeoShapeQueryField other = (GeoShapeQueryField) o; return Objects.equals(this.indexedShape, other.indexedShape) && Objects.equals(this.relation, other.relation) - && this.shape.equals(other.shape); + && Objects.equals(this.shape, other.shape); } } diff --git a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/XyShapeQueryField.java b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/XyShapeQueryField.java index 7e624d233..8dd5dfccc 100644 --- a/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/XyShapeQueryField.java +++ b/java-client/src/generated/java/org/opensearch/client/opensearch/_types/query_dsl/XyShapeQueryField.java @@ -25,7 +25,6 @@ import org.opensearch.client.json.ObjectDeserializer; import org.opensearch.client.json.PlainJsonSerializable; import org.opensearch.client.opensearch._types.GeoShapeRelation; -import org.opensearch.client.util.ApiTypeHelper; import org.opensearch.client.util.CopyableBuilder; import org.opensearch.client.util.ObjectBuilder; import org.opensearch.client.util.ObjectBuilderBase; @@ -43,7 +42,7 @@ public class XyShapeQueryField implements PlainJsonSerializable, ToCopyableBuild @Nullable private final GeoShapeRelation relation; - @Nonnull + @Nullable private final XyShape shape; // --------------------------------------------------------------------------------------------- @@ -51,7 +50,7 @@ public class XyShapeQueryField implements PlainJsonSerializable, ToCopyableBuild private XyShapeQueryField(Builder builder) { this.indexedShape = builder.indexedShape; this.relation = builder.relation; - this.shape = ApiTypeHelper.requireNonNull(builder.shape, this, "shape"); + this.shape = builder.shape; } public static XyShapeQueryField of(Function> fn) { @@ -75,9 +74,9 @@ public final GeoShapeRelation relation() { } /** - * Required - API name: {@code shape} + * API name: {@code shape} */ - @Nonnull + @Nullable public final XyShape shape() { return this.shape; } @@ -103,8 +102,10 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { this.relation.serialize(generator, mapper); } - generator.writeKey("shape"); - this.shape.serialize(generator, mapper); + if (this.shape != null) { + generator.writeKey("shape"); + this.shape.serialize(generator, mapper); + } } // --------------------------------------------------------------------------------------------- @@ -128,6 +129,7 @@ public static class Builder extends ObjectBuilderBase implements CopyableBuilder private FieldLookup indexedShape; @Nullable private GeoShapeRelation relation; + @Nullable private XyShape shape; public Builder() {} @@ -177,16 +179,16 @@ public final Builder relation(@Nullable GeoShapeRelation value) { } /** - * Required - API name: {@code shape} + * API name: {@code shape} */ @Nonnull - public final Builder shape(XyShape value) { + public final Builder shape(@Nullable XyShape value) { this.shape = value; return this; } /** - * Required - API name: {@code shape} + * API name: {@code shape} */ @Nonnull public final Builder shape(Function> fn) { @@ -228,7 +230,7 @@ public int hashCode() { int result = 17; result = 31 * result + Objects.hashCode(this.indexedShape); result = 31 * result + Objects.hashCode(this.relation); - result = 31 * result + this.shape.hashCode(); + result = 31 * result + Objects.hashCode(this.shape); return result; } @@ -239,6 +241,6 @@ public boolean equals(Object o) { XyShapeQueryField other = (XyShapeQueryField) o; return Objects.equals(this.indexedShape, other.indexedShape) && Objects.equals(this.relation, other.relation) - && this.shape.equals(other.shape); + && Objects.equals(this.shape, other.shape); } } diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/GeoShapeQueryFieldTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/GeoShapeQueryFieldTest.java index d599ed433..3378546a5 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/GeoShapeQueryFieldTest.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/GeoShapeQueryFieldTest.java @@ -19,4 +19,13 @@ public void toBuilder() { assertEquals(toJson(copied), toJson(origin)); } + + @Test + public void indexedShapeOnly() { + GeoShapeQueryField field = new GeoShapeQueryField.Builder().indexedShape(i -> i.id("id").index("shapes").path("location")).build(); + + assertNull(field.shape()); + assertEquals("id", field.indexedShape().id()); + assertEquals("{\"indexed_shape\":{\"id\":\"id\",\"index\":\"shapes\",\"path\":\"location\"}}", toJson(field)); + } } diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/XyShapeQueryFieldTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/XyShapeQueryFieldTest.java index 9149f4bae..ae1c085e5 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/XyShapeQueryFieldTest.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/XyShapeQueryFieldTest.java @@ -43,4 +43,13 @@ public void toBuilder() { assertEquals(toJson(copied), toJson(origin)); } + + @Test + public void indexedShapeOnly() { + XyShapeQueryField field = new XyShapeQueryField.Builder().indexedShape(i -> i.id("id").index("shapes").path("location")).build(); + + assertNull(field.shape()); + assertEquals("id", field.indexedShape().id()); + assertEquals("{\"indexed_shape\":{\"id\":\"id\",\"index\":\"shapes\",\"path\":\"location\"}}", toJson(field)); + } } diff --git a/java-codegen/opensearch-openapi.yaml b/java-codegen/opensearch-openapi.yaml index b4829f72a..6c8648842 100644 --- a/java-codegen/opensearch-openapi.yaml +++ b/java-codegen/opensearch-openapi.yaml @@ -48620,8 +48620,6 @@ components: $ref: '#/components/schemas/_common.query_dsl___GeoShape' relation: $ref: '#/components/schemas/_common___GeoShapeRelation' - required: - - shape _common.query_dsl___GeoValidationMethod: type: string enum: @@ -50318,8 +50316,6 @@ components: $ref: '#/components/schemas/_common.query_dsl___XyShape' relation: $ref: '#/components/schemas/_common___GeoShapeRelation' - required: - - shape _common.query_dsl___ZeroTermsQuery: type: string enum: