Skip to content

Commit 86b00b8

Browse files
authored
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.
1 parent 3d67915 commit 86b00b8

File tree

17 files changed

+19
-126
lines changed

17 files changed

+19
-126
lines changed

core/src/main/java/org/elasticsearch/index/query/ConstantScoreQueryBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
public class ConstantScoreQueryBuilder extends AbstractQueryBuilder<ConstantScoreQueryBuilder> {
4040
public static final String NAME = "constant_score";
4141

42-
private static final ParseField INNER_QUERY_FIELD = new ParseField("filter", "query");
42+
private static final ParseField INNER_QUERY_FIELD = new ParseField("filter");
4343

4444
private final QueryBuilder filterBuilder;
4545

core/src/main/java/org/elasticsearch/index/query/MatchPhraseQueryBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
*/
3939
public class MatchPhraseQueryBuilder extends AbstractQueryBuilder<MatchPhraseQueryBuilder> {
4040
public static final String NAME = "match_phrase";
41-
public static final ParseField SLOP_FIELD = new ParseField("slop", "phrase_slop");
41+
public static final ParseField SLOP_FIELD = new ParseField("slop");
4242

4343
private final String fieldName;
4444

core/src/main/java/org/elasticsearch/index/query/MoreLikeThisQueryBuilder.java

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,12 @@ private interface Field {
9696
ParseField FIELDS = new ParseField("fields");
9797
ParseField LIKE = new ParseField("like");
9898
ParseField UNLIKE = new ParseField("unlike");
99-
ParseField LIKE_TEXT = new ParseField("like_text").withAllDeprecated("like");
100-
ParseField IDS = new ParseField("ids").withAllDeprecated("like");
101-
ParseField DOCS = new ParseField("docs").withAllDeprecated("like");
10299
ParseField MAX_QUERY_TERMS = new ParseField("max_query_terms");
103100
ParseField MIN_TERM_FREQ = new ParseField("min_term_freq");
104101
ParseField MIN_DOC_FREQ = new ParseField("min_doc_freq");
105102
ParseField MAX_DOC_FREQ = new ParseField("max_doc_freq");
106-
ParseField MIN_WORD_LENGTH = new ParseField("min_word_length", "min_word_len");
107-
ParseField MAX_WORD_LENGTH = new ParseField("max_word_length", "max_word_len");
103+
ParseField MIN_WORD_LENGTH = new ParseField("min_word_length");
104+
ParseField MAX_WORD_LENGTH = new ParseField("max_word_length");
108105
ParseField STOP_WORDS = new ParseField("stop_words");
109106
ParseField ANALYZER = new ParseField("analyzer");
110107
ParseField MINIMUM_SHOULD_MATCH = new ParseField("minimum_should_match");
@@ -846,8 +843,6 @@ public static MoreLikeThisQueryBuilder fromXContent(XContentParser parser) throw
846843
parseLikeField(parser, likeTexts, likeItems);
847844
} else if (Field.UNLIKE.match(currentFieldName)) {
848845
parseLikeField(parser, unlikeTexts, unlikeItems);
849-
} else if (Field.LIKE_TEXT.match(currentFieldName)) {
850-
likeTexts.add(parser.text());
851846
} else if (Field.MAX_QUERY_TERMS.match(currentFieldName)) {
852847
maxQueryTerms = parser.intValue();
853848
} else if (Field.MIN_TERM_FREQ.match(currentFieldName)) {
@@ -891,20 +886,6 @@ public static MoreLikeThisQueryBuilder fromXContent(XContentParser parser) throw
891886
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
892887
parseLikeField(parser, unlikeTexts, unlikeItems);
893888
}
894-
} else if (Field.IDS.match(currentFieldName)) {
895-
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
896-
if (!token.isValue()) {
897-
throw new IllegalArgumentException("ids array element should only contain ids");
898-
}
899-
likeItems.add(new Item(null, null, parser.text()));
900-
}
901-
} else if (Field.DOCS.match(currentFieldName)) {
902-
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
903-
if (token != XContentParser.Token.START_OBJECT) {
904-
throw new IllegalArgumentException("docs array element should include an object");
905-
}
906-
likeItems.add(Item.parse(parser, new Item()));
907-
}
908889
} else if (Field.STOP_WORDS.match(currentFieldName)) {
909890
stopWords = new ArrayList<>();
910891
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {

core/src/main/java/org/elasticsearch/index/query/MultiMatchQueryBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public class MultiMatchQueryBuilder extends AbstractQueryBuilder<MultiMatchQuery
5858
public static final boolean DEFAULT_LENIENCY = MatchQuery.DEFAULT_LENIENCY;
5959
public static final MatchQuery.ZeroTermsQuery DEFAULT_ZERO_TERMS_QUERY = MatchQuery.DEFAULT_ZERO_TERMS_QUERY;
6060

61-
private static final ParseField SLOP_FIELD = new ParseField("slop", "phrase_slop");
61+
private static final ParseField SLOP_FIELD = new ParseField("slop");
6262
private static final ParseField ZERO_TERMS_QUERY_FIELD = new ParseField("zero_terms_query");
6363
private static final ParseField LENIENT_FIELD = new ParseField("lenient");
6464
private static final ParseField CUTOFF_FREQUENCY_FIELD = new ParseField("cutoff_frequency");

core/src/main/java/org/elasticsearch/index/query/PrefixQueryBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
public class PrefixQueryBuilder extends AbstractQueryBuilder<PrefixQueryBuilder> implements MultiTermQueryBuilder {
4444
public static final String NAME = "prefix";
4545

46-
private static final ParseField PREFIX_FIELD = new ParseField("value", "prefix");
46+
private static final ParseField PREFIX_FIELD = new ParseField("value");
4747
private static final ParseField REWRITE_FIELD = new ParseField("rewrite");
4848

4949
private final String fieldName;

core/src/main/java/org/elasticsearch/index/query/RangeQueryBuilder.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,8 @@ public class RangeQueryBuilder extends AbstractQueryBuilder<RangeQueryBuilder> i
5353
public static final boolean DEFAULT_INCLUDE_UPPER = true;
5454
public static final boolean DEFAULT_INCLUDE_LOWER = true;
5555

56-
private static final ParseField FIELDDATA_FIELD = new ParseField("fielddata").withAllDeprecated("[no replacement]");
57-
private static final ParseField NAME_FIELD = new ParseField("_name")
58-
.withAllDeprecated("query name is not supported in short version of range query");
59-
public static final ParseField LTE_FIELD = new ParseField("lte", "le");
60-
public static final ParseField GTE_FIELD = new ParseField("gte", "ge");
56+
public static final ParseField LTE_FIELD = new ParseField("lte");
57+
public static final ParseField GTE_FIELD = new ParseField("gte");
6158
public static final ParseField FROM_FIELD = new ParseField("from");
6259
public static final ParseField TO_FIELD = new ParseField("to");
6360
private static final ParseField INCLUDE_LOWER_FIELD = new ParseField("include_lower");
@@ -416,13 +413,7 @@ public static RangeQueryBuilder fromXContent(XContentParser parser) throws IOExc
416413
}
417414
}
418415
} else if (token.isValue()) {
419-
if (NAME_FIELD.match(currentFieldName)) {
420-
queryName = parser.text();
421-
} else if (FIELDDATA_FIELD.match(currentFieldName)) {
422-
// ignore
423-
} else {
424416
throw new ParsingException(parser.getTokenLocation(), "[range] query does not support [" + currentFieldName + "]");
425-
}
426417
}
427418
}
428419

core/src/main/java/org/elasticsearch/index/query/RegexpQueryBuilder.java

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ public class RegexpQueryBuilder extends AbstractQueryBuilder<RegexpQueryBuilder>
4747
public static final int DEFAULT_FLAGS_VALUE = RegexpFlag.ALL.value();
4848
public static final int DEFAULT_MAX_DETERMINIZED_STATES = Operations.DEFAULT_MAX_DETERMINIZED_STATES;
4949

50-
private static final ParseField NAME_FIELD = new ParseField("_name")
51-
.withAllDeprecated("query name is not supported in short version of regexp query");
5250
private static final ParseField FLAGS_VALUE_FIELD = new ParseField("flags_value");
5351
private static final ParseField MAX_DETERMINIZED_STATES_FIELD = new ParseField("max_determinized_states");
5452
private static final ParseField FLAGS_FIELD = new ParseField("flags");
@@ -219,13 +217,9 @@ public static RegexpQueryBuilder fromXContent(XContentParser parser) throws IOEx
219217
}
220218
}
221219
} else {
222-
if (NAME_FIELD.match(currentFieldName)) {
223-
queryName = parser.text();
224-
} else {
225-
throwParsingExceptionOnMultipleFields(NAME, parser.getTokenLocation(), fieldName, parser.currentName());
226-
fieldName = currentFieldName;
227-
value = parser.textOrNull();
228-
}
220+
throwParsingExceptionOnMultipleFields(NAME, parser.getTokenLocation(), fieldName, parser.currentName());
221+
fieldName = currentFieldName;
222+
value = parser.textOrNull();
229223
}
230224
}
231225

core/src/main/java/org/elasticsearch/index/query/support/QueryParsers.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
public final class QueryParsers {
2727

28-
public static final ParseField CONSTANT_SCORE = new ParseField("constant_score", "constant_score_auto", "constant_score_filter");
28+
public static final ParseField CONSTANT_SCORE = new ParseField("constant_score");
2929
public static final ParseField SCORING_BOOLEAN = new ParseField("scoring_boolean");
3030
public static final ParseField CONSTANT_SCORE_BOOLEAN = new ParseField("constant_score_boolean");
3131
public static final ParseField TOP_TERMS = new ParseField("top_terms_");

core/src/test/java/org/elasticsearch/index/query/RangeQueryBuilderTests.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -382,21 +382,6 @@ public void testNamedQueryParsing() throws IOException {
382382
" }\n" +
383383
"}";
384384
assertNotNull(parseQuery(json));
385-
386-
final String deprecatedJson =
387-
"{\n" +
388-
" \"range\" : {\n" +
389-
" \"timestamp\" : {\n" +
390-
" \"from\" : \"2015-01-01 00:00:00\",\n" +
391-
" \"to\" : \"now\",\n" +
392-
" \"boost\" : 1.0\n" +
393-
" },\n" +
394-
" \"_name\" : \"my_range\"\n" +
395-
" }\n" +
396-
"}";
397-
398-
assertNotNull(parseQuery(deprecatedJson));
399-
assertWarnings("Deprecated field [_name] used, replaced by [query name is not supported in short version of range query]");
400385
}
401386

402387
public void testRewriteDateToMatchAll() throws IOException {

docs/reference/query-dsl/multi-term-rewrite.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ boost.
1919
into a should clause in a boolean query, and keeps the scores as
2020
computed by the query. Note that typically such scores are meaningless
2121
to the user, and require non-trivial CPU to compute, so it's almost
22-
always better to use `constant_score_auto`. This rewrite method will hit
22+
always better to use `constant_score`. This rewrite method will hit
2323
too many clauses failure if it exceeds the boolean query limit (defaults
2424
to `1024`).
2525
* `constant_score_boolean`: Similar to `scoring_boolean` except scores

0 commit comments

Comments
 (0)