From 26019f2a1556ccb17f6711c941351b332fe51ae7 Mon Sep 17 00:00:00 2001 From: Alan Woodward Date: Mon, 20 Jun 2022 12:43:41 +0100 Subject: [PATCH] Remove default-value parameters from non-core queries (#87813) This slims down the representations of all remaining queries not in the core * percolate * function_score * script_score * pinned Relates to #76515 --- .../percolator/PercolateQueryBuilder.java | 2 +- .../query/functionscore/FunctionScoreQueryBuilder.java | 10 +++++++--- .../query/functionscore/ScriptScoreQueryBuilder.java | 2 +- .../test/errorquery/ErrorQueryBuilder.java | 2 +- .../core/transform/MockDeprecatedQueryBuilder.java | 2 +- .../xpack/searchbusinessrules/PinnedQueryBuilder.java | 2 +- .../searchbusinessrules/PinnedQueryBuilderTests.java | 6 ++---- 7 files changed, 14 insertions(+), 12 deletions(-) diff --git a/modules/percolator/src/main/java/org/elasticsearch/percolator/PercolateQueryBuilder.java b/modules/percolator/src/main/java/org/elasticsearch/percolator/PercolateQueryBuilder.java index 391f0a8b628c9..ee8e3370ef6cd 100644 --- a/modules/percolator/src/main/java/org/elasticsearch/percolator/PercolateQueryBuilder.java +++ b/modules/percolator/src/main/java/org/elasticsearch/percolator/PercolateQueryBuilder.java @@ -324,7 +324,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep builder.field(INDEXED_DOCUMENT_FIELD_VERSION.getPreferredName(), indexedDocumentVersion); } } - printBoostAndQueryName(builder); + boostAndQueryNameToXContent(builder); builder.endObject(); } diff --git a/server/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryBuilder.java b/server/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryBuilder.java index b8d4c34915eb9..7ce903f717854 100644 --- a/server/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryBuilder.java +++ b/server/src/main/java/org/elasticsearch/index/query/functionscore/FunctionScoreQueryBuilder.java @@ -239,15 +239,19 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep } builder.endArray(); - builder.field(SCORE_MODE_FIELD.getPreferredName(), scoreMode.name().toLowerCase(Locale.ROOT)); + if (scoreMode != DEFAULT_SCORE_MODE) { + builder.field(SCORE_MODE_FIELD.getPreferredName(), scoreMode.name().toLowerCase(Locale.ROOT)); + } if (boostMode != null) { builder.field(BOOST_MODE_FIELD.getPreferredName(), boostMode.name().toLowerCase(Locale.ROOT)); } - builder.field(MAX_BOOST_FIELD.getPreferredName(), maxBoost); + if (maxBoost != FunctionScoreQuery.DEFAULT_MAX_BOOST) { + builder.field(MAX_BOOST_FIELD.getPreferredName(), maxBoost); + } if (minScore != null) { builder.field(MIN_SCORE_FIELD.getPreferredName(), minScore); } - printBoostAndQueryName(builder); + boostAndQueryNameToXContent(builder); builder.endObject(); } diff --git a/server/src/main/java/org/elasticsearch/index/query/functionscore/ScriptScoreQueryBuilder.java b/server/src/main/java/org/elasticsearch/index/query/functionscore/ScriptScoreQueryBuilder.java index 75041386dae38..d658cb678bcf1 100644 --- a/server/src/main/java/org/elasticsearch/index/query/functionscore/ScriptScoreQueryBuilder.java +++ b/server/src/main/java/org/elasticsearch/index/query/functionscore/ScriptScoreQueryBuilder.java @@ -125,7 +125,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep if (minScore != null) { builder.field(MIN_SCORE_FIELD.getPreferredName(), minScore); } - printBoostAndQueryName(builder); + boostAndQueryNameToXContent(builder); builder.endObject(); } diff --git a/test/external-modules/error-query/src/main/java/org/elasticsearch/test/errorquery/ErrorQueryBuilder.java b/test/external-modules/error-query/src/main/java/org/elasticsearch/test/errorquery/ErrorQueryBuilder.java index e4c8296f45177..5343069eb6d65 100644 --- a/test/external-modules/error-query/src/main/java/org/elasticsearch/test/errorquery/ErrorQueryBuilder.java +++ b/test/external-modules/error-query/src/main/java/org/elasticsearch/test/errorquery/ErrorQueryBuilder.java @@ -115,7 +115,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep builder.endObject(); } builder.endArray(); - printBoostAndQueryName(builder); + boostAndQueryNameToXContent(builder); builder.endObject(); } diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/transform/MockDeprecatedQueryBuilder.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/transform/MockDeprecatedQueryBuilder.java index 6cf8f66b06514..c5c438964144d 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/transform/MockDeprecatedQueryBuilder.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/transform/MockDeprecatedQueryBuilder.java @@ -66,7 +66,7 @@ protected void doWriteTo(StreamOutput out) throws IOException {} @Override protected void doXContent(XContentBuilder builder, Params params) throws IOException { builder.startObject(NAME); - printBoostAndQueryName(builder); + boostAndQueryNameToXContent(builder); builder.endObject(); } diff --git a/x-pack/plugin/search-business-rules/src/main/java/org/elasticsearch/xpack/searchbusinessrules/PinnedQueryBuilder.java b/x-pack/plugin/search-business-rules/src/main/java/org/elasticsearch/xpack/searchbusinessrules/PinnedQueryBuilder.java index 064af3f8577b0..d6cc37bcf13a1 100644 --- a/x-pack/plugin/search-business-rules/src/main/java/org/elasticsearch/xpack/searchbusinessrules/PinnedQueryBuilder.java +++ b/x-pack/plugin/search-business-rules/src/main/java/org/elasticsearch/xpack/searchbusinessrules/PinnedQueryBuilder.java @@ -302,7 +302,7 @@ protected void doXContent(XContentBuilder builder, Params params) throws IOExcep } builder.endArray(); } - printBoostAndQueryName(builder); + boostAndQueryNameToXContent(builder); builder.endObject(); } diff --git a/x-pack/plugin/search-business-rules/src/test/java/org/elasticsearch/xpack/searchbusinessrules/PinnedQueryBuilderTests.java b/x-pack/plugin/search-business-rules/src/test/java/org/elasticsearch/xpack/searchbusinessrules/PinnedQueryBuilderTests.java index 12e94bd820522..b8880330d3d30 100644 --- a/x-pack/plugin/search-business-rules/src/test/java/org/elasticsearch/xpack/searchbusinessrules/PinnedQueryBuilderTests.java +++ b/x-pack/plugin/search-business-rules/src/test/java/org/elasticsearch/xpack/searchbusinessrules/PinnedQueryBuilderTests.java @@ -158,8 +158,7 @@ public void testIdsFromJson() throws IOException { } } }, - "ids": [ "1", "2" ], - "boost": 1.0 + "ids": [ "1", "2" ] } }"""; @@ -181,8 +180,7 @@ public void testDocsFromJson() throws IOException { } } }, - "docs": [ { "_index": "test", "_id": "1" }, { "_index": "test", "_id": "2" } ], - "boost": 1.0 + "docs": [ { "_index": "test", "_id": "1" }, { "_index": "test", "_id": "2" } ] } }""";