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

Deprecate BoolQueryBuilder's mustNot field #53125

Merged
merged 2 commits into from
Mar 6, 2020
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 @@ -52,8 +52,8 @@ public class BoolQueryBuilder extends AbstractQueryBuilder<BoolQueryBuilder> {

public static final boolean ADJUST_PURE_NEGATIVE_DEFAULT = true;

private static final ParseField MUSTNOT = new ParseField("mustNot"); // TODO deprecate?
private static final ParseField MUST_NOT = new ParseField("must_not");
private static final ParseField MUST_NOT = new ParseField("must_not")
.withDeprecation("mustNot");
private static final ParseField FILTER = new ParseField("filter");
private static final ParseField SHOULD = new ParseField("should");
private static final ParseField MUST = new ParseField("must");
Expand Down Expand Up @@ -279,8 +279,6 @@ private static void doXArrayContent(ParseField field, List<QueryBuilder> clauses
SHOULD);
PARSER.declareObjectArray((builder, clauses) -> clauses.forEach(builder::mustNot), (p, c) -> parseInnerQueryBuilder(p),
MUST_NOT);
PARSER.declareObjectArray((builder, clauses) -> clauses.forEach(builder::mustNot), (p, c) -> parseInnerQueryBuilder(p),
MUSTNOT); // TODO should we deprecate this version?
PARSER.declareObjectArray((builder, clauses) -> clauses.forEach(builder::filter), (p, c) -> parseInnerQueryBuilder(p),
FILTER);
PARSER.declareBoolean(BoolQueryBuilder::adjustPureNegative, ADJUST_PURE_NEGATIVE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ protected Map<String, BoolQueryBuilder> getAlternateVersions() {
}
if (tempQueryBuilder.mustNot().size() > 0) {
QueryBuilder mustNot = tempQueryBuilder.mustNot().get(0);
contentString += (randomBoolean() ? "\"must_not\": " : "\"mustNot\": ") + mustNot.toString() + ",";
contentString += "\"must_not\":" + mustNot.toString() + ",";
expectedQuery.mustNot(mustNot);
}
if (tempQueryBuilder.should().size() > 0) {
Expand Down Expand Up @@ -297,6 +297,14 @@ public void testUnknownQueryName() throws IOException {

}

public void testDeprecation() throws IOException {
String query = "{\"bool\" : {\"mustNot\" : { \"match_all\" : { } } } }";
QueryBuilder q = parseQuery(query);
QueryBuilder expected = new BoolQueryBuilder().mustNot(new MatchAllQueryBuilder());
assertEquals(expected, q);
assertWarnings("Deprecated field [mustNot] used, expected [must_not] instead");
}

public void testRewrite() throws IOException {
BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
boolean mustRewrite = false;
Expand Down