Skip to content

Commit

Permalink
Fix minimum_should_match behaviour on null value
Browse files Browse the repository at this point in the history
Until 7.7 we used to ignore `null` values for `minimum_should_match` in `bool`
queries. An internal refactoring has changed this so now we get a parsing error.
While `null` should not a common value here, we should restore the old behaviour
at least on the 7.x lines.

Closes elastic#56812
  • Loading branch information
Christoph Büscher committed May 15, 2020
1 parent fd812d2 commit 4f5ed9e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ private static void doXArrayContent(ParseField field, List<QueryBuilder> clauses
PARSER.declareObjectArray((builder, clauses) -> clauses.forEach(builder::filter), (p, c) -> parseInnerQueryBuilder(p),
FILTER);
PARSER.declareBoolean(BoolQueryBuilder::adjustPureNegative, ADJUST_PURE_NEGATIVE);
PARSER.declareField(BoolQueryBuilder::minimumShouldMatch, (p, c) -> p.text(),
PARSER.declareField(BoolQueryBuilder::minimumShouldMatch, (p, c) -> p.textOrNull(),
MINIMUM_SHOULD_MATCH, ObjectParser.ValueType.VALUE);
PARSER.declareString(BoolQueryBuilder::queryName, NAME_FIELD);
PARSER.declareFloat(BoolQueryBuilder::boost, BOOST_FIELD);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,12 @@ public void testMinimumShouldMatchNumber() throws IOException {
assertEquals("1", builder.minimumShouldMatch());
}

public void testMinimumShouldMatchNull() throws IOException {
String query = "{\"bool\" : {\"must\" : { \"term\" : { \"field\" : \"value\" } }, \"minimum_should_match\" : null } }";
BoolQueryBuilder builder = (BoolQueryBuilder) parseQuery(query);
assertEquals(null, builder.minimumShouldMatch());
}

/**
* test that unknown query names in the clauses throw an error
*/
Expand Down

0 comments on commit 4f5ed9e

Please sign in to comment.