From 0dceb5980a146e56f00d3b5c694271d45c6aa0e4 Mon Sep 17 00:00:00 2001 From: Chris Danisch Date: Wed, 4 Sep 2024 14:09:38 -0700 Subject: [PATCH] Fix queries losing inherited data when toBuilder is called. (#1181) * Fixes https://github.com/opensearch-project/opensearch-java/issues/1172 Calling `toBuilder` on classes which implement `QueryBase` will now preserve `boost` and `queryName`. Signed-off-by: Chris Danisch * Updated changelog Signed-off-by: Chris Danisch * Added toBuilder to QueryBase instead. Signed-off-by: Chris Danisch --------- Signed-off-by: Chris Danisch (cherry picked from commit 020e0b053cb0d33ec44a8692a3ae558178ecc160) Signed-off-by: Thomas Farr --- CHANGELOG.md | 1 + .../client/opensearch/_types/query_dsl/BoolQuery.java | 2 +- .../client/opensearch/_types/query_dsl/BoostingQuery.java | 2 +- .../opensearch/_types/query_dsl/CombinedFieldsQuery.java | 2 +- .../opensearch/_types/query_dsl/CommonTermsQuery.java | 2 +- .../opensearch/_types/query_dsl/ConstantScoreQuery.java | 2 +- .../client/opensearch/_types/query_dsl/DisMaxQuery.java | 2 +- .../opensearch/_types/query_dsl/DistanceFeatureQuery.java | 2 +- .../client/opensearch/_types/query_dsl/ExistsQuery.java | 2 +- .../opensearch/_types/query_dsl/FunctionScoreQuery.java | 2 +- .../client/opensearch/_types/query_dsl/FuzzyQuery.java | 2 +- .../opensearch/_types/query_dsl/GeoBoundingBoxQuery.java | 2 +- .../opensearch/_types/query_dsl/GeoDistanceQuery.java | 2 +- .../client/opensearch/_types/query_dsl/GeoShapeQuery.java | 2 +- .../client/opensearch/_types/query_dsl/HasChildQuery.java | 2 +- .../client/opensearch/_types/query_dsl/HasParentQuery.java | 6 +++++- .../client/opensearch/_types/query_dsl/HybridQuery.java | 2 +- .../client/opensearch/_types/query_dsl/IdsQuery.java | 2 +- .../client/opensearch/_types/query_dsl/IntervalsQuery.java | 2 +- .../client/opensearch/_types/query_dsl/KnnQuery.java | 2 +- .../opensearch/_types/query_dsl/MatchBoolPrefixQuery.java | 2 +- .../_types/query_dsl/MatchPhrasePrefixQuery.java | 2 +- .../opensearch/_types/query_dsl/MatchPhraseQuery.java | 2 +- .../client/opensearch/_types/query_dsl/MatchQuery.java | 2 +- .../opensearch/_types/query_dsl/MoreLikeThisQuery.java | 2 +- .../opensearch/_types/query_dsl/MultiMatchQuery.java | 2 +- .../client/opensearch/_types/query_dsl/NestedQuery.java | 2 +- .../client/opensearch/_types/query_dsl/NeuralQuery.java | 2 +- .../client/opensearch/_types/query_dsl/ParentIdQuery.java | 2 +- .../client/opensearch/_types/query_dsl/PercolateQuery.java | 2 +- .../client/opensearch/_types/query_dsl/PinnedQuery.java | 2 +- .../client/opensearch/_types/query_dsl/PrefixQuery.java | 2 +- .../client/opensearch/_types/query_dsl/QueryBase.java | 4 ++++ .../opensearch/_types/query_dsl/QueryStringQuery.java | 2 +- .../client/opensearch/_types/query_dsl/RangeQuery.java | 2 +- .../opensearch/_types/query_dsl/RankFeatureQuery.java | 2 +- .../client/opensearch/_types/query_dsl/RegexpQuery.java | 2 +- .../client/opensearch/_types/query_dsl/ScriptQuery.java | 2 +- .../opensearch/_types/query_dsl/ScriptScoreQuery.java | 2 +- .../_types/query_dsl/SimpleQueryStringQuery.java | 2 +- .../opensearch/_types/query_dsl/SpanContainingQuery.java | 2 +- .../opensearch/_types/query_dsl/SpanFieldMaskingQuery.java | 2 +- .../client/opensearch/_types/query_dsl/SpanFirstQuery.java | 2 +- .../opensearch/_types/query_dsl/SpanMultiTermQuery.java | 2 +- .../client/opensearch/_types/query_dsl/SpanNearQuery.java | 2 +- .../client/opensearch/_types/query_dsl/SpanNotQuery.java | 2 +- .../client/opensearch/_types/query_dsl/SpanOrQuery.java | 2 +- .../client/opensearch/_types/query_dsl/SpanTermQuery.java | 2 +- .../opensearch/_types/query_dsl/SpanWithinQuery.java | 2 +- .../client/opensearch/_types/query_dsl/TermQuery.java | 2 +- .../client/opensearch/_types/query_dsl/TermsQuery.java | 2 +- .../client/opensearch/_types/query_dsl/TermsSetQuery.java | 2 +- .../client/opensearch/_types/query_dsl/TypeQuery.java | 2 +- .../client/opensearch/_types/query_dsl/WildcardQuery.java | 7 ++++++- .../client/opensearch/_types/query_dsl/WrapperQuery.java | 2 +- .../client/opensearch/_types/query_dsl/XyShapeQuery.java | 2 +- .../{BoostringQueryTest.java => BoostingQueryTest.java} | 2 +- .../client/opensearch/_types/query_dsl/MatchQueryTest.java | 2 +- 58 files changed, 70 insertions(+), 56 deletions(-) rename java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/{BoostringQueryTest.java => BoostingQueryTest.java} (94%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2587bc4ac5..ab689025bb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### Removed ### Fixed +- Fix queries not preserving boost and name when converted to builders ([#1181](https://github.com/opensearch-project/opensearch-java/pull/1181)) ### Security diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/BoolQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/BoolQuery.java index d8d4a6f915..8127122be3 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/BoolQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/BoolQuery.java @@ -172,7 +172,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().filter(filter).minimumShouldMatch(minimumShouldMatch).must(must).mustNot(mustNot).should(should); + return toBuilder(new Builder()).filter(filter).minimumShouldMatch(minimumShouldMatch).must(must).mustNot(mustNot).should(should); } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/BoostingQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/BoostingQuery.java index 4aa7ed3a2a..93bf82624c 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/BoostingQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/BoostingQuery.java @@ -111,7 +111,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().negativeBoost(negativeBoost).negative(negative).positive(positive); + return toBuilder(new Builder()).negativeBoost(negativeBoost).negative(negative).positive(positive); } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/CombinedFieldsQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/CombinedFieldsQuery.java index 35c8571c36..88a966ff2b 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/CombinedFieldsQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/CombinedFieldsQuery.java @@ -174,7 +174,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().fields(fields) + return toBuilder(new Builder()).fields(fields) .query(query) .autoGenerateSynonymsPhraseQuery(autoGenerateSynonymsPhraseQuery) .operator(operator) diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/CommonTermsQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/CommonTermsQuery.java index e0bd23f71d..cb9bd377b9 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/CommonTermsQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/CommonTermsQuery.java @@ -183,7 +183,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().field(field) + return toBuilder(new Builder()).field(field) .analyzer(analyzer) .cutoffFrequency(cutoffFrequency) .highFreqOperator(highFreqOperator) diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/ConstantScoreQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/ConstantScoreQuery.java index a958275eb5..544e9ade3b 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/ConstantScoreQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/ConstantScoreQuery.java @@ -85,7 +85,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().filter(filter); + return toBuilder(new Builder()).filter(filter); } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/DisMaxQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/DisMaxQuery.java index f03de385e9..24cba1c8c5 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/DisMaxQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/DisMaxQuery.java @@ -112,7 +112,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().queries(queries).tieBreaker(tieBreaker); + return toBuilder(new Builder()).queries(queries).tieBreaker(tieBreaker); } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/DistanceFeatureQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/DistanceFeatureQuery.java index 781c750ebf..3995f165d9 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/DistanceFeatureQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/DistanceFeatureQuery.java @@ -112,7 +112,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().origin(origin).pivot(pivot).field(field); + return toBuilder(new Builder()).origin(origin).pivot(pivot).field(field); } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/ExistsQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/ExistsQuery.java index 1a5b8f0e8c..a05229cab5 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/ExistsQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/ExistsQuery.java @@ -85,7 +85,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().field(field); + return toBuilder(new Builder()).field(field); } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/FunctionScoreQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/FunctionScoreQuery.java index 34124bbaa8..84f23d80e5 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/FunctionScoreQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/FunctionScoreQuery.java @@ -178,7 +178,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().boostMode(boostMode) + return toBuilder(new Builder()).boostMode(boostMode) .functions(functions) .maxBoost(maxBoost) .minScore(minScore) diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/FuzzyQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/FuzzyQuery.java index 91fc3b1a66..295ea1143b 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/FuzzyQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/FuzzyQuery.java @@ -186,7 +186,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().field(field) + return toBuilder(new Builder()).field(field) .value(value) .maxExpansions(maxExpansions) .prefixLength(prefixLength) diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/GeoBoundingBoxQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/GeoBoundingBoxQuery.java index 272ab31a7e..2525c26185 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/GeoBoundingBoxQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/GeoBoundingBoxQuery.java @@ -149,7 +149,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().field(field) + return toBuilder(new Builder()).field(field) .boundingBox(boundingBox) .type(type) .validationMethod(validationMethod) diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/GeoDistanceQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/GeoDistanceQuery.java index 31b14157bb..2fc92cf470 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/GeoDistanceQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/GeoDistanceQuery.java @@ -147,7 +147,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().field(field).location(location); + return toBuilder(new Builder()).field(field).location(location); } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/GeoShapeQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/GeoShapeQuery.java index 0047aaac67..daae1138b8 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/GeoShapeQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/GeoShapeQuery.java @@ -113,7 +113,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().field(field).shape(shape); + return toBuilder(new Builder()).field(field).shape(shape); } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/HasChildQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/HasChildQuery.java index 2e2cdd1cf1..a89a2b19e7 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/HasChildQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/HasChildQuery.java @@ -184,7 +184,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().ignoreUnmapped(ignoreUnmapped) + return toBuilder(new Builder()).ignoreUnmapped(ignoreUnmapped) .innerHits(innerHits) .maxChildren(maxChildren) .minChildren(minChildren) diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/HasParentQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/HasParentQuery.java index 4019246161..755ad185b8 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/HasParentQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/HasParentQuery.java @@ -152,7 +152,11 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().ignoreUnmapped(ignoreUnmapped).innerHits(innerHits).parentType(parentType).query(query).score(score); + return toBuilder(new Builder()).ignoreUnmapped(ignoreUnmapped) + .innerHits(innerHits) + .parentType(parentType) + .query(query) + .score(score); } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/HybridQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/HybridQuery.java index 932cbb93d6..1f3048504a 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/HybridQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/HybridQuery.java @@ -56,7 +56,7 @@ public Query.Kind _queryKind() { } public HybridQuery.Builder toBuilder() { - return new HybridQuery.Builder().queries(queries); + return toBuilder(new Builder()).queries(queries); } public static class Builder extends QueryBase.AbstractBuilder implements ObjectBuilder { diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/IdsQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/IdsQuery.java index 687158d529..74e9cb02d1 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/IdsQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/IdsQuery.java @@ -95,7 +95,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().values(values); + return toBuilder(new Builder()).values(values); } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/IntervalsQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/IntervalsQuery.java index d5c655db15..1386e77ef7 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/IntervalsQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/IntervalsQuery.java @@ -252,7 +252,7 @@ public void serialize(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder()._kind(_kind)._value(_value).field(field); + return toBuilder(new Builder())._kind(_kind)._value(_value).field(field); } public static class Builder extends QueryBase.AbstractBuilder implements ObjectBuilder { diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/KnnQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/KnnQuery.java index 175fe6e11a..596752f47c 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/KnnQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/KnnQuery.java @@ -108,7 +108,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().field(field).vector(vector).k(k).filter(filter); + return toBuilder(new Builder()).field(field).vector(vector).k(k).filter(filter); } /** diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/MatchBoolPrefixQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/MatchBoolPrefixQuery.java index b370342728..fbd877201f 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/MatchBoolPrefixQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/MatchBoolPrefixQuery.java @@ -235,7 +235,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().field(field) + return toBuilder(new Builder()).field(field) .analyzer(analyzer) .fuzziness(fuzziness) .fuzzyRewrite(fuzzyRewrite) diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/MatchPhrasePrefixQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/MatchPhrasePrefixQuery.java index bba0cf42f7..b275eb5a27 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/MatchPhrasePrefixQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/MatchPhrasePrefixQuery.java @@ -168,7 +168,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().field(field) + return toBuilder(new Builder()).field(field) .analyzer(analyzer) .maxExpansions(maxExpansions) .query(query) diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/MatchPhraseQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/MatchPhraseQuery.java index 2e7ac94bec..c6c68dcd54 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/MatchPhraseQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/MatchPhraseQuery.java @@ -151,7 +151,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().field(field).analyzer(analyzer).query(query).slop(slop).zeroTermsQuery(zeroTermsQuery); + return toBuilder(new Builder()).field(field).analyzer(analyzer).query(query).slop(slop).zeroTermsQuery(zeroTermsQuery); } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/MatchQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/MatchQuery.java index cab702a5b2..750c5d2948 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/MatchQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/MatchQuery.java @@ -307,7 +307,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().field(field) + return toBuilder(new Builder()).field(field) .analyzer(analyzer) .autoGenerateSynonymsPhraseQuery(autoGenerateSynonymsPhraseQuery) .cutoffFrequency(cutoffFrequency) diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/MoreLikeThisQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/MoreLikeThisQuery.java index f75d0dce97..18a28faa79 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/MoreLikeThisQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/MoreLikeThisQuery.java @@ -415,7 +415,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().analyzer(analyzer) + return toBuilder(new Builder()).analyzer(analyzer) .boostTerms(boostTerms) .failOnUnsupportedField(failOnUnsupportedField) .fields(fields) diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/MultiMatchQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/MultiMatchQuery.java index 192fbc5b70..fcab41899e 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/MultiMatchQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/MultiMatchQuery.java @@ -363,7 +363,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().analyzer(analyzer) + return toBuilder(new Builder()).analyzer(analyzer) .autoGenerateSynonymsPhraseQuery(autoGenerateSynonymsPhraseQuery) .cutoffFrequency(cutoffFrequency) .fields(fields) diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/NestedQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/NestedQuery.java index 997d553728..e3e6fc8e49 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/NestedQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/NestedQuery.java @@ -151,7 +151,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().ignoreUnmapped(ignoreUnmapped).innerHits(innerHits).path(path).query(query).scoreMode(scoreMode); + return toBuilder(new Builder()).ignoreUnmapped(ignoreUnmapped).innerHits(innerHits).path(path).query(query).scoreMode(scoreMode); } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/NeuralQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/NeuralQuery.java index baadf3e849..9984f912d0 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/NeuralQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/NeuralQuery.java @@ -152,7 +152,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().field(field).queryText(queryText).queryImage(queryImage).k(k).modelId(modelId).filter(filter); + return toBuilder(new Builder()).field(field).queryText(queryText).queryImage(queryImage).k(k).modelId(modelId).filter(filter); } /** diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/ParentIdQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/ParentIdQuery.java index 62d0212560..7664f45ed1 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/ParentIdQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/ParentIdQuery.java @@ -124,7 +124,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().id(id).ignoreUnmapped(ignoreUnmapped).type(type); + return toBuilder(new Builder()).id(id).ignoreUnmapped(ignoreUnmapped).type(type); } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/PercolateQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/PercolateQuery.java index 947b08889a..b224ff47b6 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/PercolateQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/PercolateQuery.java @@ -228,7 +228,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().document(document) + return toBuilder(new Builder()).document(document) .documents(documents) .field(field) .id(id) diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/PinnedQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/PinnedQuery.java index eabd1d8222..04a710c1c5 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/PinnedQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/PinnedQuery.java @@ -197,7 +197,7 @@ public void serialize(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder()._kind(_kind)._value(_value).organic(organic); + return toBuilder(new Builder())._kind(_kind)._value(_value).organic(organic); } public static class Builder extends QueryBase.AbstractBuilder { diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/PrefixQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/PrefixQuery.java index b64fbd5328..c7efcc35f3 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/PrefixQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/PrefixQuery.java @@ -135,7 +135,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().field(field).value(value).rewrite(rewrite).value(value).caseInsensitive(caseInsensitive); + return toBuilder(new Builder()).field(field).value(value).rewrite(rewrite).value(value).caseInsensitive(caseInsensitive); } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/QueryBase.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/QueryBase.java index b08abdbd6a..90b788fca2 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/QueryBase.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/QueryBase.java @@ -98,6 +98,10 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } + protected > BuilderT toBuilder(BuilderT builder) { + return builder.queryName(queryName).boost(boost); + } + protected abstract static class AbstractBuilder> extends ObjectBuilderBase { @Nullable private Float boost; diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/QueryStringQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/QueryStringQuery.java index d1c074b648..05e5c8165a 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/QueryStringQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/QueryStringQuery.java @@ -497,7 +497,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().allowLeadingWildcard(allowLeadingWildcard) + return toBuilder(new Builder()).allowLeadingWildcard(allowLeadingWildcard) .analyzer(analyzer) .analyzeWildcard(analyzeWildcard) .autoGenerateSynonymsPhraseQuery(autoGenerateSynonymsPhraseQuery) diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/RangeQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/RangeQuery.java index 60e85dc4c3..ec3dda228f 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/RangeQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/RangeQuery.java @@ -225,7 +225,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().field(field).gt(gt).gte(gte).lt(lt).lte(lte).from(from).to(to).format(format).timeZone(timeZone); + return toBuilder(new Builder()).field(field).gt(gt).gte(gte).lt(lt).lte(lte).from(from).to(to).format(format).timeZone(timeZone); } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/RankFeatureQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/RankFeatureQuery.java index c2d01d2e80..8614fb3082 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/RankFeatureQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/RankFeatureQuery.java @@ -155,7 +155,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().field(field).saturation(saturation).log(log).linear(linear).sigmoid(sigmoid); + return toBuilder(new Builder()).field(field).saturation(saturation).log(log).linear(linear).sigmoid(sigmoid); } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/RegexpQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/RegexpQuery.java index 25c9b0445f..fdcef27d76 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/RegexpQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/RegexpQuery.java @@ -168,7 +168,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().field(field) + return toBuilder(new Builder()).field(field) .value(value) .caseInsensitive(caseInsensitive) .flags(flags) diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/ScriptQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/ScriptQuery.java index 252d6a3217..ec16228cd6 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/ScriptQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/ScriptQuery.java @@ -86,7 +86,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().script(script); + return toBuilder(new Builder()).script(script); } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/ScriptScoreQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/ScriptScoreQuery.java index 126309de89..6db3199f5f 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/ScriptScoreQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/ScriptScoreQuery.java @@ -117,7 +117,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().minScore(minScore).query(query).script(script); + return toBuilder(new Builder()).minScore(minScore).query(query).script(script); } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/SimpleQueryStringQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/SimpleQueryStringQuery.java index 803230a525..bb7c894fc0 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/SimpleQueryStringQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/SimpleQueryStringQuery.java @@ -294,7 +294,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().analyzer(analyzer) + return toBuilder(new Builder()).analyzer(analyzer) .analyzeWildcard(analyzeWildcard) .autoGenerateSynonymsPhraseQuery(autoGenerateSynonymsPhraseQuery) .defaultOperator(defaultOperator) diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/SpanContainingQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/SpanContainingQuery.java index 0a24e78415..130e867453 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/SpanContainingQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/SpanContainingQuery.java @@ -106,7 +106,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().big(big).little(little); + return toBuilder(new Builder()).big(big).little(little); } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/SpanFieldMaskingQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/SpanFieldMaskingQuery.java index 3908eb21a4..61db26c521 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/SpanFieldMaskingQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/SpanFieldMaskingQuery.java @@ -106,7 +106,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().field(field).query(query); + return toBuilder(new Builder()).field(field).query(query); } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/SpanFirstQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/SpanFirstQuery.java index 0f7646a8de..214712a6e7 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/SpanFirstQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/SpanFirstQuery.java @@ -106,7 +106,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().end(end).match(match); + return toBuilder(new Builder()).end(end).match(match); } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/SpanMultiTermQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/SpanMultiTermQuery.java index be51d14fc4..f29bfd9889 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/SpanMultiTermQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/SpanMultiTermQuery.java @@ -96,7 +96,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().match(match); + return toBuilder(new Builder()).match(match); } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/SpanNearQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/SpanNearQuery.java index 69ce1fc39f..4f87b7893d 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/SpanNearQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/SpanNearQuery.java @@ -137,7 +137,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().clauses(clauses).inOrder(inOrder).slop(slop); + return toBuilder(new Builder()).clauses(clauses).inOrder(inOrder).slop(slop); } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/SpanNotQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/SpanNotQuery.java index a37941b53f..13e3f36e66 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/SpanNotQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/SpanNotQuery.java @@ -159,7 +159,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().dist(dist).exclude(exclude).include(include).post(post).pre(pre); + return toBuilder(new Builder()).dist(dist).exclude(exclude).include(include).post(post).pre(pre); } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/SpanOrQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/SpanOrQuery.java index a38b1b9159..ad3ae45559 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/SpanOrQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/SpanOrQuery.java @@ -102,7 +102,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().clauses(clauses); + return toBuilder(new Builder()).clauses(clauses); } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/SpanTermQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/SpanTermQuery.java index 0d8772fe3c..adfcf813ea 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/SpanTermQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/SpanTermQuery.java @@ -107,7 +107,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().field(field).value(value); + return toBuilder(new Builder()).field(field).value(value); } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/SpanWithinQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/SpanWithinQuery.java index 3a1c6a8cf4..66a3df46ce 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/SpanWithinQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/SpanWithinQuery.java @@ -106,7 +106,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().big(big).little(little); + return toBuilder(new Builder()).big(big).little(little); } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/TermQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/TermQuery.java index 589ec8da8b..a14ae01a10 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/TermQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/TermQuery.java @@ -119,7 +119,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().field(field).value(value).caseInsensitive(caseInsensitive); + return toBuilder(new Builder()).field(field).value(value).caseInsensitive(caseInsensitive); } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/TermsQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/TermsQuery.java index 0319969897..284e6e7c46 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/TermsQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/TermsQuery.java @@ -94,7 +94,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().field(field).terms(terms); + return toBuilder(new Builder()).field(field).terms(terms); } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/TermsSetQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/TermsSetQuery.java index 78e365173e..1351aa9e5d 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/TermsSetQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/TermsSetQuery.java @@ -144,7 +144,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().field(field) + return toBuilder(new Builder()).field(field) .minimumShouldMatchField(minimumShouldMatchField) .minimumShouldMatchScript(minimumShouldMatchScript) .terms(terms); diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/TypeQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/TypeQuery.java index 215eccca14..ac334bcdc2 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/TypeQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/TypeQuery.java @@ -85,7 +85,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().value(value); + return toBuilder(new Builder()).value(value); } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/WildcardQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/WildcardQuery.java index 724f933829..d03d9cad3a 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/WildcardQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/WildcardQuery.java @@ -168,7 +168,12 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().field(field).value(value).caseInsensitive(caseInsensitive).rewrite(rewrite).value(value).wildcard(wildcard); + return toBuilder(new Builder()).field(field) + .value(value) + .caseInsensitive(caseInsensitive) + .rewrite(rewrite) + .value(value) + .wildcard(wildcard); } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/WrapperQuery.java b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/WrapperQuery.java index b87ea9b3fc..d4d7c2ecc2 100644 --- a/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/WrapperQuery.java +++ b/java-client/src/main/java/org/opensearch/client/opensearch/_types/query_dsl/WrapperQuery.java @@ -88,7 +88,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public Builder toBuilder() { - return new Builder().query(query); + return toBuilder(new Builder()).query(query); } // --------------------------------------------------------------------------------------------- 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 index 279b59563f..46d3bad07e 100644 --- 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 @@ -112,7 +112,7 @@ protected void serializeInternal(JsonGenerator generator, JsonpMapper mapper) { } public XyShapeQuery.Builder toBuilder() { - return new XyShapeQuery.Builder().field(field).xyShape(xyShape); + return toBuilder(new Builder()).field(field).xyShape(xyShape); } // --------------------------------------------------------------------------------------------- diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/BoostringQueryTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/BoostingQueryTest.java similarity index 94% rename from java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/BoostringQueryTest.java rename to java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/BoostingQueryTest.java index 3f954491b8..93535d7cb7 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/BoostringQueryTest.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/BoostingQueryTest.java @@ -12,7 +12,7 @@ import org.opensearch.client.opensearch._types.FieldValue; import org.opensearch.client.opensearch.model.ModelTestCase; -public class BoostringQueryTest extends ModelTestCase { +public class BoostingQueryTest extends ModelTestCase { @Test public void toBuilder() { BoostingQuery origin = new BoostingQuery.Builder().negativeBoost(1.0f) diff --git a/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/MatchQueryTest.java b/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/MatchQueryTest.java index c0aa2f49f1..6e942f3806 100644 --- a/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/MatchQueryTest.java +++ b/java-client/src/test/java/org/opensearch/client/opensearch/_types/query_dsl/MatchQueryTest.java @@ -15,7 +15,7 @@ public class MatchQueryTest extends ModelTestCase { @Test public void toBuilder() { - MatchQuery origin = new MatchQuery.Builder().field("field").query(FieldValue.of("1")).build(); + MatchQuery origin = new MatchQuery.Builder().field("field").query(FieldValue.of("1")).queryName("name").boost(5f).build(); MatchQuery copied = origin.toBuilder().build(); assertEquals(toJson(copied), toJson(origin));