Skip to content

Commit cf9f3b5

Browse files
committed
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 b63b023 commit cf9f3b5

File tree

18 files changed

+37
-127
lines changed

18 files changed

+37
-127
lines changed

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

+1-1
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

+1-1
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

+2-21
Original file line numberDiff line numberDiff line change
@@ -97,15 +97,12 @@ private interface Field {
9797
ParseField FIELDS = new ParseField("fields");
9898
ParseField LIKE = new ParseField("like");
9999
ParseField UNLIKE = new ParseField("unlike");
100-
ParseField LIKE_TEXT = new ParseField("like_text").withAllDeprecated("like");
101-
ParseField IDS = new ParseField("ids").withAllDeprecated("like");
102-
ParseField DOCS = new ParseField("docs").withAllDeprecated("like");
103100
ParseField MAX_QUERY_TERMS = new ParseField("max_query_terms");
104101
ParseField MIN_TERM_FREQ = new ParseField("min_term_freq");
105102
ParseField MIN_DOC_FREQ = new ParseField("min_doc_freq");
106103
ParseField MAX_DOC_FREQ = new ParseField("max_doc_freq");
107-
ParseField MIN_WORD_LENGTH = new ParseField("min_word_length", "min_word_len");
108-
ParseField MAX_WORD_LENGTH = new ParseField("max_word_length", "max_word_len");
104+
ParseField MIN_WORD_LENGTH = new ParseField("min_word_length");
105+
ParseField MAX_WORD_LENGTH = new ParseField("max_word_length");
109106
ParseField STOP_WORDS = new ParseField("stop_words");
110107
ParseField ANALYZER = new ParseField("analyzer");
111108
ParseField MINIMUM_SHOULD_MATCH = new ParseField("minimum_should_match");
@@ -847,8 +844,6 @@ public static MoreLikeThisQueryBuilder fromXContent(XContentParser parser) throw
847844
parseLikeField(parser, likeTexts, likeItems);
848845
} else if (Field.UNLIKE.match(currentFieldName)) {
849846
parseLikeField(parser, unlikeTexts, unlikeItems);
850-
} else if (Field.LIKE_TEXT.match(currentFieldName)) {
851-
likeTexts.add(parser.text());
852847
} else if (Field.MAX_QUERY_TERMS.match(currentFieldName)) {
853848
maxQueryTerms = parser.intValue();
854849
} else if (Field.MIN_TERM_FREQ.match(currentFieldName)) {
@@ -892,20 +887,6 @@ public static MoreLikeThisQueryBuilder fromXContent(XContentParser parser) throw
892887
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
893888
parseLikeField(parser, unlikeTexts, unlikeItems);
894889
}
895-
} else if (Field.IDS.match(currentFieldName)) {
896-
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
897-
if (!token.isValue()) {
898-
throw new IllegalArgumentException("ids array element should only contain ids");
899-
}
900-
likeItems.add(new Item(null, null, parser.text()));
901-
}
902-
} else if (Field.DOCS.match(currentFieldName)) {
903-
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {
904-
if (token != XContentParser.Token.START_OBJECT) {
905-
throw new IllegalArgumentException("docs array element should include an object");
906-
}
907-
likeItems.add(Item.parse(parser, new Item()));
908-
}
909890
} else if (Field.STOP_WORDS.match(currentFieldName)) {
910891
stopWords = new ArrayList<>();
911892
while ((token = parser.nextToken()) != XContentParser.Token.END_ARRAY) {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class MultiMatchQueryBuilder extends AbstractQueryBuilder<MultiMatchQuery
5959
public static final boolean DEFAULT_LENIENCY = MatchQuery.DEFAULT_LENIENCY;
6060
public static final MatchQuery.ZeroTermsQuery DEFAULT_ZERO_TERMS_QUERY = MatchQuery.DEFAULT_ZERO_TERMS_QUERY;
6161

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

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

+1-1
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

+2-11
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");
@@ -403,13 +400,7 @@ public static RangeQueryBuilder fromXContent(XContentParser parser) throws IOExc
403400
}
404401
}
405402
} else if (token.isValue()) {
406-
if (NAME_FIELD.match(currentFieldName)) {
407-
queryName = parser.text();
408-
} else if (FIELDDATA_FIELD.match(currentFieldName)) {
409-
// ignore
410-
} else {
411403
throw new ParsingException(parser.getTokenLocation(), "[range] query does not support [" + currentFieldName + "]");
412-
}
413404
}
414405
}
415406

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

+3-9
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

+1-1
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

-15
Original file line numberDiff line numberDiff line change
@@ -389,21 +389,6 @@ public void testNamedQueryParsing() throws IOException {
389389
" }\n" +
390390
"}";
391391
assertNotNull(parseQuery(json));
392-
393-
final String deprecatedJson =
394-
"{\n" +
395-
" \"range\" : {\n" +
396-
" \"timestamp\" : {\n" +
397-
" \"from\" : \"2015-01-01 00:00:00\",\n" +
398-
" \"to\" : \"now\",\n" +
399-
" \"boost\" : 1.0\n" +
400-
" },\n" +
401-
" \"_name\" : \"my_range\"\n" +
402-
" }\n" +
403-
"}";
404-
405-
assertNotNull(parseQuery(deprecatedJson));
406-
assertWarnings("Deprecated field [_name] used, replaced by [query name is not supported in short version of range query]");
407392
}
408393

409394
public void testRewriteDateToMatchAll() throws IOException {

docs/reference/migration/migrate_6_0/search.asciidoc

+18-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414

1515
* The `geo_bbox` query (a synonym for the `geo_bounding_box` query) has been removed
1616

17-
* The `mlt` query (a synonym for the `more_like_this` query) has been removed
17+
* The `mlt` query (a synonym for the `more_like_this` query) has been removed.
18+
19+
* The deprecated `like_text`, `ids` and `docs` parameters (all synonyms for `like`) of the `more_like_this` query have
20+
been removed. Also the deprecated `min_word_len` (a synonym for `min_word_length`) and `max_word_len`
21+
(a synonym for `max_word_length`) have been removed.
1822

1923
* The `fuzzy_match` and `match_fuzzy` query (synonyma for the `match` query) have been removed
2024

@@ -80,6 +84,19 @@
8084
setting the `type`, the `match_phrase` or `match_phrase_prefix` should be used. The `slop` removed from
8185
the `match` query but is supported for `match_phrase` and `match_phrase_prefix`.
8286

87+
* The deprecated `phrase_slop` parameter (a synonym for the `slop` parameter) of the `match_phrase` query has been removed.
88+
89+
* The deprecated `query` parameter (a synonym for the `filter` parameter) of the `constant_score` query has been removed.
90+
91+
* The deprecated `phrase_slop` parameter (a synonym for the `slop` parameter) of the `multi_match` query has been removed.
92+
93+
* The deprecated `prefix` parameter (a synonym for the `value` parameter) of the `prefix` query has been removed.
94+
95+
* The deprecated `le` (a synonym for `lte`) and `ge` (a synonym for `gte`) parameter of the `range` query have been removed.
96+
97+
* The deprecated multi term rewrite parameters `constant_score_auto`, `constant_score_filter` (synonyms for `constant_score`)
98+
have been removed.
99+
83100
==== Search shards API
84101

85102
The search shards API no longer accepts the `type` url parameter, which didn't

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

+1-1
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

docs/reference/query-dsl/prefix-query.asciidoc

-13
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,6 @@ GET /_search
2828
--------------------------------------------------
2929
// CONSOLE
3030

31-
Or with the `prefix` deprecated[5.0.0, Use `value`] syntax:
32-
33-
[source,js]
34-
--------------------------------------------------
35-
GET /_search
36-
{ "query": {
37-
"prefix" : { "user" : { "prefix" : "ki", "boost" : 2.0 } }
38-
}
39-
}
40-
--------------------------------------------------
41-
// CONSOLE
42-
// TEST[warning:Deprecated field [prefix] used, expected [value] instead]
43-
4431
This multi term query allows you to control how it gets rewritten using the
4532
<<query-dsl-multi-term-rewrite,rewrite>>
4633
parameter.

modules/parent-join/src/main/java/org/elasticsearch/join/query/HasChildQueryBuilder.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ public class HasChildQueryBuilder extends AbstractQueryBuilder<HasChildQueryBuil
7676
*/
7777
public static final boolean DEFAULT_IGNORE_UNMAPPED = false;
7878

79-
private static final ParseField QUERY_FIELD = new ParseField("query", "filter");
80-
private static final ParseField TYPE_FIELD = new ParseField("type", "child_type");
79+
private static final ParseField QUERY_FIELD = new ParseField("query");
80+
private static final ParseField TYPE_FIELD = new ParseField("type");
8181
private static final ParseField MAX_CHILDREN_FIELD = new ParseField("max_children");
8282
private static final ParseField MIN_CHILDREN_FIELD = new ParseField("min_children");
8383
private static final ParseField SCORE_MODE_FIELD = new ParseField("score_mode");

modules/parent-join/src/main/java/org/elasticsearch/join/query/HasParentQueryBuilder.java

+2-13
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,8 @@ public class HasParentQueryBuilder extends AbstractQueryBuilder<HasParentQueryBu
6363
*/
6464
public static final boolean DEFAULT_IGNORE_UNMAPPED = false;
6565

66-
private static final ParseField QUERY_FIELD = new ParseField("query", "filter");
67-
private static final ParseField SCORE_MODE_FIELD = new ParseField("score_mode").withAllDeprecated("score");
68-
private static final ParseField TYPE_FIELD = new ParseField("parent_type", "type");
66+
private static final ParseField QUERY_FIELD = new ParseField("query");
67+
private static final ParseField TYPE_FIELD = new ParseField("parent_type");
6968
private static final ParseField SCORE_FIELD = new ParseField("score");
7069
private static final ParseField INNER_HITS_FIELD = new ParseField("inner_hits");
7170
private static final ParseField IGNORE_UNMAPPED_FIELD = new ParseField("ignore_unmapped");
@@ -307,16 +306,6 @@ public static HasParentQueryBuilder fromXContent(XContentParser parser) throws I
307306
} else if (token.isValue()) {
308307
if (TYPE_FIELD.match(currentFieldName)) {
309308
parentType = parser.text();
310-
} else if (SCORE_MODE_FIELD.match(currentFieldName)) {
311-
String scoreModeValue = parser.text();
312-
if ("score".equals(scoreModeValue)) {
313-
score = true;
314-
} else if ("none".equals(scoreModeValue)) {
315-
score = false;
316-
} else {
317-
throw new ParsingException(parser.getTokenLocation(), "[has_parent] query does not support [" +
318-
scoreModeValue + "] as an option for score_mode");
319-
}
320309
} else if (SCORE_FIELD.match(currentFieldName)) {
321310
score = parser.booleanValue();
322311
} else if (IGNORE_UNMAPPED_FIELD.match(currentFieldName)) {

modules/parent-join/src/main/java/org/elasticsearch/join/query/ParentIdQueryBuilder.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public final class ParentIdQueryBuilder extends AbstractQueryBuilder<ParentIdQue
5353
public static final boolean DEFAULT_IGNORE_UNMAPPED = false;
5454

5555
private static final ParseField ID_FIELD = new ParseField("id");
56-
private static final ParseField TYPE_FIELD = new ParseField("type", "child_type");
56+
private static final ParseField TYPE_FIELD = new ParseField("type");
5757
private static final ParseField IGNORE_UNMAPPED_FIELD = new ParseField("ignore_unmapped");
5858

5959
private final String type;

modules/parent-join/src/test/java/org/elasticsearch/join/query/HasParentQueryBuilderTests.java

-17
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,10 @@
2323
import org.apache.lucene.search.Query;
2424
import org.apache.lucene.search.join.ScoreMode;
2525
import org.elasticsearch.Version;
26-
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
2726
import org.elasticsearch.cluster.metadata.IndexMetaData;
2827
import org.elasticsearch.common.compress.CompressedXContent;
2928
import org.elasticsearch.common.settings.Settings;
30-
import org.elasticsearch.common.xcontent.ToXContent;
3129
import org.elasticsearch.common.xcontent.XContentBuilder;
32-
import org.elasticsearch.common.xcontent.XContentFactory;
3330
import org.elasticsearch.index.mapper.MapperService;
3431
import org.elasticsearch.index.query.IdsQueryBuilder;
3532
import org.elasticsearch.index.query.InnerHitBuilder;
@@ -198,20 +195,6 @@ public void testIllegalValues() throws IOException {
198195
assertThat(qse.getMessage(), equalTo("[has_parent] join field [join_field] doesn't hold [just_a_type] as a parent"));
199196
}
200197

201-
public void testDeprecatedXContent() throws IOException {
202-
XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint();
203-
builder.startObject();
204-
builder.startObject("has_parent");
205-
builder.field("query");
206-
new TermQueryBuilder("a", "a").toXContent(builder, ToXContent.EMPTY_PARAMS);
207-
builder.field("type", "foo"); // deprecated
208-
builder.endObject();
209-
builder.endObject();
210-
HasParentQueryBuilder queryBuilder = (HasParentQueryBuilder) parseQuery(builder.string());
211-
assertEquals("foo", queryBuilder.type());
212-
assertWarnings("Deprecated field [type] used, expected [parent_type] instead");
213-
}
214-
215198
public void testToQueryInnerQueryType() throws IOException {
216199
String[] searchTypes = new String[]{TYPE};
217200
QueryShardContext shardContext = createShardContext();

modules/parent-join/src/test/java/org/elasticsearch/join/query/LegacyHasParentQueryBuilderTests.java

-17
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,6 @@
2626
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
2727
import org.elasticsearch.common.compress.CompressedXContent;
2828
import org.elasticsearch.common.settings.Settings;
29-
import org.elasticsearch.common.xcontent.ToXContent;
30-
import org.elasticsearch.common.xcontent.XContentBuilder;
31-
import org.elasticsearch.common.xcontent.XContentFactory;
3229
import org.elasticsearch.index.mapper.MapperService;
3330
import org.elasticsearch.index.query.IdsQueryBuilder;
3431
import org.elasticsearch.index.query.InnerHitBuilder;
@@ -186,20 +183,6 @@ public void testIllegalValues() throws IOException {
186183
assertThat(qse.getMessage(), equalTo("[has_parent] no child types found for type [just_a_type]"));
187184
}
188185

189-
public void testDeprecatedXContent() throws IOException {
190-
XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint();
191-
builder.startObject();
192-
builder.startObject("has_parent");
193-
builder.field("query");
194-
new TermQueryBuilder("a", "a").toXContent(builder, ToXContent.EMPTY_PARAMS);
195-
builder.field("type", "foo"); // deprecated
196-
builder.endObject();
197-
builder.endObject();
198-
HasParentQueryBuilder queryBuilder = (HasParentQueryBuilder) parseQuery(builder.string());
199-
assertEquals("foo", queryBuilder.type());
200-
assertWarnings("Deprecated field [type] used, expected [parent_type] instead");
201-
}
202-
203186
public void testToQueryInnerQueryType() throws IOException {
204187
String[] searchTypes = new String[]{CHILD_TYPE};
205188
QueryShardContext shardContext = createShardContext();

qa/query-builder-bwc/src/test/java/org/elasticsearch/bwc/QueryBuilderBWCIT.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public class QueryBuilderBWCIT extends ESRestTestCase {
101101
.tieBreaker(0.01f)
102102
);
103103
addCandidate(
104-
"\"constant_score\": {\"query\": {\"match_all\": {}}, \"boost\": 0.1}",
104+
"\"constant_score\": {\"filter\": {\"match_all\": {}}, \"boost\": 0.1}",
105105
new ConstantScoreQueryBuilder(new MatchAllQueryBuilder()).boost(0.1f)
106106
);
107107
addCandidate(

0 commit comments

Comments
 (0)