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

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

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

+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");
@@ -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

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

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