From 9ccccaf500e31675b0fb5ebae8deeb33226d8586 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christoph=20B=C3=BCscher?= Date: Wed, 20 Sep 2017 16:22:21 +0200 Subject: [PATCH] Remove parse field deprecations in query builders (#26711) The `fielddata` field and the use of the `_name` field in the short syntax of the range query have been deprecated in 5.0 and can be removed. The same goes for the deprecated `score_mode` field in HasParentQueryBuilder, the deprecated `like_text`, `ids` and `docs` parameter in the `more_like_this` query, the deprecated query name in the short version of the `regexp` query, and several deprecated alternative field names in other query builders. --- .../query/ConstantScoreQueryBuilder.java | 2 +- .../index/query/MatchPhraseQueryBuilder.java | 2 +- .../index/query/MoreLikeThisQueryBuilder.java | 23 ++----------------- .../index/query/MultiMatchQueryBuilder.java | 2 +- .../index/query/PrefixQueryBuilder.java | 2 +- .../index/query/RangeQueryBuilder.java | 13 ++--------- .../index/query/RegexpQueryBuilder.java | 12 +++------- .../index/query/support/QueryParsers.java | 2 +- .../index/query/RangeQueryBuilderTests.java | 15 ------------ .../migration/migrate_6_0/search.asciidoc | 19 ++++++++++++++- .../query-dsl/multi-term-rewrite.asciidoc | 2 +- .../reference/query-dsl/prefix-query.asciidoc | 13 ----------- .../join/query/HasChildQueryBuilder.java | 4 ++-- .../join/query/HasParentQueryBuilder.java | 15 ++---------- .../join/query/ParentIdQueryBuilder.java | 2 +- .../query/HasParentQueryBuilderTests.java | 17 -------------- .../LegacyHasParentQueryBuilderTests.java | 17 -------------- .../elasticsearch/bwc/QueryBuilderBWCIT.java | 2 +- 18 files changed, 37 insertions(+), 127 deletions(-) diff --git a/core/src/main/java/org/elasticsearch/index/query/ConstantScoreQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/ConstantScoreQueryBuilder.java index f1e3f7aea7780..df4e31c5955a9 100644 --- a/core/src/main/java/org/elasticsearch/index/query/ConstantScoreQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/ConstantScoreQueryBuilder.java @@ -39,7 +39,7 @@ public class ConstantScoreQueryBuilder extends AbstractQueryBuilder { public static final String NAME = "constant_score"; - private static final ParseField INNER_QUERY_FIELD = new ParseField("filter", "query"); + private static final ParseField INNER_QUERY_FIELD = new ParseField("filter"); private final QueryBuilder filterBuilder; diff --git a/core/src/main/java/org/elasticsearch/index/query/MatchPhraseQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/MatchPhraseQueryBuilder.java index 1865e30744302..1bdab8d78a81d 100644 --- a/core/src/main/java/org/elasticsearch/index/query/MatchPhraseQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/MatchPhraseQueryBuilder.java @@ -38,7 +38,7 @@ */ public class MatchPhraseQueryBuilder extends AbstractQueryBuilder { public static final String NAME = "match_phrase"; - public static final ParseField SLOP_FIELD = new ParseField("slop", "phrase_slop"); + public static final ParseField SLOP_FIELD = new ParseField("slop"); private final String fieldName; diff --git a/core/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java index 94faa63fff746..53dfe232748a5 100644 --- a/core/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java @@ -96,15 +96,12 @@ private interface Field { ParseField FIELDS = new ParseField("fields"); ParseField LIKE = new ParseField("like"); ParseField UNLIKE = new ParseField("unlike"); - ParseField LIKE_TEXT = new ParseField("like_text").withAllDeprecated("like"); - ParseField IDS = new ParseField("ids").withAllDeprecated("like"); - ParseField DOCS = new ParseField("docs").withAllDeprecated("like"); ParseField MAX_QUERY_TERMS = new ParseField("max_query_terms"); ParseField MIN_TERM_FREQ = new ParseField("min_term_freq"); ParseField MIN_DOC_FREQ = new ParseField("min_doc_freq"); ParseField MAX_DOC_FREQ = new ParseField("max_doc_freq"); - ParseField MIN_WORD_LENGTH = new ParseField("min_word_length", "min_word_len"); - ParseField MAX_WORD_LENGTH = new ParseField("max_word_length", "max_word_len"); + ParseField MIN_WORD_LENGTH = new ParseField("min_word_length"); + ParseField MAX_WORD_LENGTH = new ParseField("max_word_length"); ParseField STOP_WORDS = new ParseField("stop_words"); ParseField ANALYZER = new ParseField("analyzer"); ParseField MINIMUM_SHOULD_MATCH = new ParseField("minimum_should_match"); @@ -846,8 +843,6 @@ public static MoreLikeThisQueryBuilder fromXContent(XContentParser parser) throw parseLikeField(parser, likeTexts, likeItems); } else if (Field.UNLIKE.match(currentFieldName)) { parseLikeField(parser, unlikeTexts, unlikeItems); - } else if (Field.LIKE_TEXT.match(currentFieldName)) { - likeTexts.add(parser.text()); } else if (Field.MAX_QUERY_TERMS.match(currentFieldName)) { maxQueryTerms = parser.intValue(); } else if (Field.MIN_TERM_FREQ.match(currentFieldName)) { @@ -891,20 +886,6 @@ public static MoreLikeThisQueryBuilder fromXContent(XContentParser parser) throw while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { parseLikeField(parser, unlikeTexts, unlikeItems); } - } else if (Field.IDS.match(currentFieldName)) { - while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { - if (!token.isValue()) { - throw new IllegalArgumentException("ids array element should only contain ids"); - } - likeItems.add(new Item(null, null, parser.text())); - } - } else if (Field.DOCS.match(currentFieldName)) { - while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { - if (token != XContentParser.Token.START_OBJECT) { - throw new IllegalArgumentException("docs array element should include an object"); - } - likeItems.add(Item.parse(parser, new Item())); - } } else if (Field.STOP_WORDS.match(currentFieldName)) { stopWords = new ArrayList<>(); while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) { diff --git a/core/src/main/java/org/elasticsearch/index/query/MultiMatchQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/MultiMatchQueryBuilder.java index ac2c9b559e86d..b439d53e6921a 100644 --- a/core/src/main/java/org/elasticsearch/index/query/MultiMatchQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/MultiMatchQueryBuilder.java @@ -58,7 +58,7 @@ public class MultiMatchQueryBuilder extends AbstractQueryBuilder implements MultiTermQueryBuilder { public static final String NAME = "prefix"; - private static final ParseField PREFIX_FIELD = new ParseField("value", "prefix"); + private static final ParseField PREFIX_FIELD = new ParseField("value"); private static final ParseField REWRITE_FIELD = new ParseField("rewrite"); private final String fieldName; diff --git a/core/src/main/java/org/elasticsearch/index/query/RangeQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/RangeQueryBuilder.java index 35350a8480ec7..14f1e16f39cbf 100644 --- a/core/src/main/java/org/elasticsearch/index/query/RangeQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/RangeQueryBuilder.java @@ -53,11 +53,8 @@ public class RangeQueryBuilder extends AbstractQueryBuilder i public static final boolean DEFAULT_INCLUDE_UPPER = true; public static final boolean DEFAULT_INCLUDE_LOWER = true; - private static final ParseField FIELDDATA_FIELD = new ParseField("fielddata").withAllDeprecated("[no replacement]"); - private static final ParseField NAME_FIELD = new ParseField("_name") - .withAllDeprecated("query name is not supported in short version of range query"); - public static final ParseField LTE_FIELD = new ParseField("lte", "le"); - public static final ParseField GTE_FIELD = new ParseField("gte", "ge"); + public static final ParseField LTE_FIELD = new ParseField("lte"); + public static final ParseField GTE_FIELD = new ParseField("gte"); public static final ParseField FROM_FIELD = new ParseField("from"); public static final ParseField TO_FIELD = new ParseField("to"); private static final ParseField INCLUDE_LOWER_FIELD = new ParseField("include_lower"); @@ -416,13 +413,7 @@ public static RangeQueryBuilder fromXContent(XContentParser parser) throws IOExc } } } else if (token.isValue()) { - if (NAME_FIELD.match(currentFieldName)) { - queryName = parser.text(); - } else if (FIELDDATA_FIELD.match(currentFieldName)) { - // ignore - } else { throw new ParsingException(parser.getTokenLocation(), "[range] query does not support [" + currentFieldName + "]"); - } } } diff --git a/core/src/main/java/org/elasticsearch/index/query/RegexpQueryBuilder.java b/core/src/main/java/org/elasticsearch/index/query/RegexpQueryBuilder.java index e6ae1b7d63a93..96290d9291259 100644 --- a/core/src/main/java/org/elasticsearch/index/query/RegexpQueryBuilder.java +++ b/core/src/main/java/org/elasticsearch/index/query/RegexpQueryBuilder.java @@ -47,8 +47,6 @@ public class RegexpQueryBuilder extends AbstractQueryBuilder public static final int DEFAULT_FLAGS_VALUE = RegexpFlag.ALL.value(); public static final int DEFAULT_MAX_DETERMINIZED_STATES = Operations.DEFAULT_MAX_DETERMINIZED_STATES; - private static final ParseField NAME_FIELD = new ParseField("_name") - .withAllDeprecated("query name is not supported in short version of regexp query"); private static final ParseField FLAGS_VALUE_FIELD = new ParseField("flags_value"); private static final ParseField MAX_DETERMINIZED_STATES_FIELD = new ParseField("max_determinized_states"); private static final ParseField FLAGS_FIELD = new ParseField("flags"); @@ -219,13 +217,9 @@ public static RegexpQueryBuilder fromXContent(XContentParser parser) throws IOEx } } } else { - if (NAME_FIELD.match(currentFieldName)) { - queryName = parser.text(); - } else { - throwParsingExceptionOnMultipleFields(NAME, parser.getTokenLocation(), fieldName, parser.currentName()); - fieldName = currentFieldName; - value = parser.textOrNull(); - } + throwParsingExceptionOnMultipleFields(NAME, parser.getTokenLocation(), fieldName, parser.currentName()); + fieldName = currentFieldName; + value = parser.textOrNull(); } } diff --git a/core/src/main/java/org/elasticsearch/index/query/support/QueryParsers.java b/core/src/main/java/org/elasticsearch/index/query/support/QueryParsers.java index 62750d275b1c6..036efa75bdaa3 100644 --- a/core/src/main/java/org/elasticsearch/index/query/support/QueryParsers.java +++ b/core/src/main/java/org/elasticsearch/index/query/support/QueryParsers.java @@ -25,7 +25,7 @@ public final class QueryParsers { - public static final ParseField CONSTANT_SCORE = new ParseField("constant_score", "constant_score_auto", "constant_score_filter"); + public static final ParseField CONSTANT_SCORE = new ParseField("constant_score"); public static final ParseField SCORING_BOOLEAN = new ParseField("scoring_boolean"); public static final ParseField CONSTANT_SCORE_BOOLEAN = new ParseField("constant_score_boolean"); public static final ParseField TOP_TERMS = new ParseField("top_terms_"); diff --git a/core/src/test/java/org/elasticsearch/index/query/RangeQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/RangeQueryBuilderTests.java index 67c3e67d39e84..4c0e2192cecb7 100644 --- a/core/src/test/java/org/elasticsearch/index/query/RangeQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/RangeQueryBuilderTests.java @@ -382,21 +382,6 @@ public void testNamedQueryParsing() throws IOException { " }\n" + "}"; assertNotNull(parseQuery(json)); - - final String deprecatedJson = - "{\n" + - " \"range\" : {\n" + - " \"timestamp\" : {\n" + - " \"from\" : \"2015-01-01 00:00:00\",\n" + - " \"to\" : \"now\",\n" + - " \"boost\" : 1.0\n" + - " },\n" + - " \"_name\" : \"my_range\"\n" + - " }\n" + - "}"; - - assertNotNull(parseQuery(deprecatedJson)); - assertWarnings("Deprecated field [_name] used, replaced by [query name is not supported in short version of range query]"); } public void testRewriteDateToMatchAll() throws IOException { diff --git a/docs/reference/migration/migrate_6_0/search.asciidoc b/docs/reference/migration/migrate_6_0/search.asciidoc index 812a9088f10d1..b7b5513366b2d 100644 --- a/docs/reference/migration/migrate_6_0/search.asciidoc +++ b/docs/reference/migration/migrate_6_0/search.asciidoc @@ -14,7 +14,11 @@ * The `geo_bbox` query (a synonym for the `geo_bounding_box` query) has been removed -* The `mlt` query (a synonym for the `more_like_this` query) has been removed +* The `mlt` query (a synonym for the `more_like_this` query) has been removed. + +* The deprecated `like_text`, `ids` and `docs` parameters (all synonyms for `like`) of the `more_like_this` query have +been removed. Also the deprecated `min_word_len` (a synonym for `min_word_length`) and `max_word_len` +(a synonym for `max_word_length`) have been removed. * The `fuzzy_match` and `match_fuzzy` query (synonyma for the `match` query) have been removed @@ -80,6 +84,19 @@ setting the `type`, the `match_phrase` or `match_phrase_prefix` should be used. The `slop` removed from the `match` query but is supported for `match_phrase` and `match_phrase_prefix`. +* The deprecated `phrase_slop` parameter (a synonym for the `slop` parameter) of the `match_phrase` query has been removed. + +* The deprecated `query` parameter (a synonym for the `filter` parameter) of the `constant_score` query has been removed. + +* The deprecated `phrase_slop` parameter (a synonym for the `slop` parameter) of the `multi_match` query has been removed. + +* The deprecated `prefix` parameter (a synonym for the `value` parameter) of the `prefix` query has been removed. + +* The deprecated `le` (a synonym for `lte`) and `ge` (a synonym for `gte`) parameter of the `range` query have been removed. + +* The deprecated multi term rewrite parameters `constant_score_auto`, `constant_score_filter` (synonyms for `constant_score`) +have been removed. + ==== Search shards API The search shards API no longer accepts the `type` url parameter, which didn't diff --git a/docs/reference/query-dsl/multi-term-rewrite.asciidoc b/docs/reference/query-dsl/multi-term-rewrite.asciidoc index 27f31340a1957..0d327a40fdea3 100644 --- a/docs/reference/query-dsl/multi-term-rewrite.asciidoc +++ b/docs/reference/query-dsl/multi-term-rewrite.asciidoc @@ -19,7 +19,7 @@ boost. into a should clause in a boolean query, and keeps the scores as computed by the query. Note that typically such scores are meaningless to the user, and require non-trivial CPU to compute, so it's almost -always better to use `constant_score_auto`. This rewrite method will hit +always better to use `constant_score`. This rewrite method will hit too many clauses failure if it exceeds the boolean query limit (defaults to `1024`). * `constant_score_boolean`: Similar to `scoring_boolean` except scores diff --git a/docs/reference/query-dsl/prefix-query.asciidoc b/docs/reference/query-dsl/prefix-query.asciidoc index 270fc925f0c50..54d69583e990c 100644 --- a/docs/reference/query-dsl/prefix-query.asciidoc +++ b/docs/reference/query-dsl/prefix-query.asciidoc @@ -28,19 +28,6 @@ GET /_search -------------------------------------------------- // CONSOLE -Or with the `prefix` deprecated[5.0.0, Use `value`] syntax: - -[source,js] --------------------------------------------------- -GET /_search -{ "query": { - "prefix" : { "user" : { "prefix" : "ki", "boost" : 2.0 } } - } -} --------------------------------------------------- -// CONSOLE -// TEST[warning:Deprecated field [prefix] used, expected [value] instead] - This multi term query allows you to control how it gets rewritten using the <> parameter. diff --git a/modules/parent-join/src/main/java/org/elasticsearch/join/query/HasChildQueryBuilder.java b/modules/parent-join/src/main/java/org/elasticsearch/join/query/HasChildQueryBuilder.java index ee362b9bca78a..bece1751a46c3 100644 --- a/modules/parent-join/src/main/java/org/elasticsearch/join/query/HasChildQueryBuilder.java +++ b/modules/parent-join/src/main/java/org/elasticsearch/join/query/HasChildQueryBuilder.java @@ -76,8 +76,8 @@ public class HasChildQueryBuilder extends AbstractQueryBuilder