Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove several parse field deprecations in query builders #26711

Merged
merged 6 commits into from
Sep 20, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
public class ConstantScoreQueryBuilder extends AbstractQueryBuilder<ConstantScoreQueryBuilder> {
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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
*/
public class MatchPhraseQueryBuilder extends AbstractQueryBuilder<MatchPhraseQueryBuilder> {
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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public class MultiMatchQueryBuilder extends AbstractQueryBuilder<MultiMatchQuery
public static final boolean DEFAULT_LENIENCY = MatchQuery.DEFAULT_LENIENCY;
public static final MatchQuery.ZeroTermsQuery DEFAULT_ZERO_TERMS_QUERY = MatchQuery.DEFAULT_ZERO_TERMS_QUERY;

private static final ParseField SLOP_FIELD = new ParseField("slop", "phrase_slop");
private static final ParseField SLOP_FIELD = new ParseField("slop");
private static final ParseField ZERO_TERMS_QUERY_FIELD = new ParseField("zero_terms_query");
private static final ParseField LENIENT_FIELD = new ParseField("lenient");
private static final ParseField CUTOFF_FREQUENCY_FIELD = new ParseField("cutoff_frequency");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
public class PrefixQueryBuilder extends AbstractQueryBuilder<PrefixQueryBuilder> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,8 @@ public class RangeQueryBuilder extends AbstractQueryBuilder<RangeQueryBuilder> 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");
Expand Down Expand Up @@ -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 + "]");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ public class RegexpQueryBuilder extends AbstractQueryBuilder<RegexpQueryBuilder>
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");
Expand Down Expand Up @@ -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();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/query-dsl/multi-term-rewrite.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 0 additions & 13 deletions docs/reference/query-dsl/prefix-query.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -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
<<query-dsl-multi-term-rewrite,rewrite>>
parameter.
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ public class HasChildQueryBuilder extends AbstractQueryBuilder<HasChildQueryBuil
*/
public static final boolean DEFAULT_IGNORE_UNMAPPED = false;

private static final ParseField QUERY_FIELD = new ParseField("query", "filter");
private static final ParseField TYPE_FIELD = new ParseField("type", "child_type");
private static final ParseField QUERY_FIELD = new ParseField("query");
private static final ParseField TYPE_FIELD = new ParseField("type");
private static final ParseField MAX_CHILDREN_FIELD = new ParseField("max_children");
private static final ParseField MIN_CHILDREN_FIELD = new ParseField("min_children");
private static final ParseField SCORE_MODE_FIELD = new ParseField("score_mode");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,8 @@ public class HasParentQueryBuilder extends AbstractQueryBuilder<HasParentQueryBu
*/
public static final boolean DEFAULT_IGNORE_UNMAPPED = false;

private static final ParseField QUERY_FIELD = new ParseField("query", "filter");
private static final ParseField SCORE_MODE_FIELD = new ParseField("score_mode").withAllDeprecated("score");
private static final ParseField TYPE_FIELD = new ParseField("parent_type", "type");
private static final ParseField QUERY_FIELD = new ParseField("query");
private static final ParseField TYPE_FIELD = new ParseField("parent_type");
private static final ParseField SCORE_FIELD = new ParseField("score");
private static final ParseField INNER_HITS_FIELD = new ParseField("inner_hits");
private static final ParseField IGNORE_UNMAPPED_FIELD = new ParseField("ignore_unmapped");
Expand Down Expand Up @@ -307,16 +306,6 @@ public static HasParentQueryBuilder fromXContent(XContentParser parser) throws I
} else if (token.isValue()) {
if (TYPE_FIELD.match(currentFieldName)) {
parentType = parser.text();
} else if (SCORE_MODE_FIELD.match(currentFieldName)) {
String scoreModeValue = parser.text();
if ("score".equals(scoreModeValue)) {
score = true;
} else if ("none".equals(scoreModeValue)) {
score = false;
} else {
throw new ParsingException(parser.getTokenLocation(), "[has_parent] query does not support [" +
scoreModeValue + "] as an option for score_mode");
}
} else if (SCORE_FIELD.match(currentFieldName)) {
score = parser.booleanValue();
} else if (IGNORE_UNMAPPED_FIELD.match(currentFieldName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public final class ParentIdQueryBuilder extends AbstractQueryBuilder<ParentIdQue
public static final boolean DEFAULT_IGNORE_UNMAPPED = false;

private static final ParseField ID_FIELD = new ParseField("id");
private static final ParseField TYPE_FIELD = new ParseField("type", "child_type");
private static final ParseField TYPE_FIELD = new ParseField("type");
private static final ParseField IGNORE_UNMAPPED_FIELD = new ParseField("ignore_unmapped");

private final String type;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,10 @@
import org.apache.lucene.search.Query;
import org.apache.lucene.search.join.ScoreMode;
import org.elasticsearch.Version;
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
import org.elasticsearch.cluster.metadata.IndexMetaData;
import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.query.IdsQueryBuilder;
import org.elasticsearch.index.query.InnerHitBuilder;
Expand Down Expand Up @@ -198,20 +195,6 @@ public void testIllegalValues() throws IOException {
assertThat(qse.getMessage(), equalTo("[has_parent] join field [join_field] doesn't hold [just_a_type] as a parent"));
}

public void testDeprecatedXContent() throws IOException {
XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint();
builder.startObject();
builder.startObject("has_parent");
builder.field("query");
new TermQueryBuilder("a", "a").toXContent(builder, ToXContent.EMPTY_PARAMS);
builder.field("type", "foo"); // deprecated
builder.endObject();
builder.endObject();
HasParentQueryBuilder queryBuilder = (HasParentQueryBuilder) parseQuery(builder.string());
assertEquals("foo", queryBuilder.type());
assertWarnings("Deprecated field [type] used, expected [parent_type] instead");
}

public void testToQueryInnerQueryType() throws IOException {
String[] searchTypes = new String[]{TYPE};
QueryShardContext shardContext = createShardContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequest;
import org.elasticsearch.common.compress.CompressedXContent;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.xcontent.ToXContent;
import org.elasticsearch.common.xcontent.XContentBuilder;
import org.elasticsearch.common.xcontent.XContentFactory;
import org.elasticsearch.index.mapper.MapperService;
import org.elasticsearch.index.query.IdsQueryBuilder;
import org.elasticsearch.index.query.InnerHitBuilder;
Expand Down Expand Up @@ -186,20 +183,6 @@ public void testIllegalValues() throws IOException {
assertThat(qse.getMessage(), equalTo("[has_parent] no child types found for type [just_a_type]"));
}

public void testDeprecatedXContent() throws IOException {
XContentBuilder builder = XContentFactory.jsonBuilder().prettyPrint();
builder.startObject();
builder.startObject("has_parent");
builder.field("query");
new TermQueryBuilder("a", "a").toXContent(builder, ToXContent.EMPTY_PARAMS);
builder.field("type", "foo"); // deprecated
builder.endObject();
builder.endObject();
HasParentQueryBuilder queryBuilder = (HasParentQueryBuilder) parseQuery(builder.string());
assertEquals("foo", queryBuilder.type());
assertWarnings("Deprecated field [type] used, expected [parent_type] instead");
}

public void testToQueryInnerQueryType() throws IOException {
String[] searchTypes = new String[]{CHILD_TYPE};
QueryShardContext shardContext = createShardContext();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public class QueryBuilderBWCIT extends ESRestTestCase {
.tieBreaker(0.01f)
);
addCandidate(
"\"constant_score\": {\"query\": {\"match_all\": {}}, \"boost\": 0.1}",
"\"constant_score\": {\"filter\": {\"match_all\": {}}, \"boost\": 0.1}",
new ConstantScoreQueryBuilder(new MatchAllQueryBuilder()).boost(0.1f)
);
addCandidate(
Expand Down