From 9b1daff9b5a9f712b369cd1f773897e7bcea703a Mon Sep 17 00:00:00 2001 From: Jim Ferenczi Date: Tue, 19 Jan 2016 09:55:29 +0100 Subject: [PATCH] Do not apply minimum-should-match on a boolean query if the coords are disabled. Fixes #15858 --- .../elasticsearch/common/lucene/search/Queries.java | 3 +++ .../index/query/BoolQueryBuilderTests.java | 11 +++++++++++ .../index/query/SimpleQueryStringBuilderTests.java | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/elasticsearch/common/lucene/search/Queries.java b/core/src/main/java/org/elasticsearch/common/lucene/search/Queries.java index 73c3fc9400d..479ad0a4c35 100644 --- a/core/src/main/java/org/elasticsearch/common/lucene/search/Queries.java +++ b/core/src/main/java/org/elasticsearch/common/lucene/search/Queries.java @@ -117,6 +117,9 @@ public class Queries { if (minimumShouldMatch == null) { return query; } + if (query.isCoordDisabled()) { + return query; + } int optionalClauses = 0; for (BooleanClause c : query.clauses()) { if (c.getOccur() == BooleanClause.Occur.SHOULD) { diff --git a/core/src/test/java/org/elasticsearch/index/query/BoolQueryBuilderTests.java b/core/src/test/java/org/elasticsearch/index/query/BoolQueryBuilderTests.java index d7740c765a7..b15513222a6 100644 --- a/core/src/test/java/org/elasticsearch/index/query/BoolQueryBuilderTests.java +++ b/core/src/test/java/org/elasticsearch/index/query/BoolQueryBuilderTests.java @@ -272,6 +272,17 @@ public class BoolQueryBuilderTests extends AbstractQueryTestCase field = fieldsIterator.next(); assertTermOrBoostQuery(booleanClause.getQuery(), field.getKey(), queryBuilder.value(), field.getValue()); } - if (queryBuilder.minimumShouldMatch() != null) { + if (queryBuilder.minimumShouldMatch() != null && !boolQuery.isCoordDisabled()) { assertThat(boolQuery.getMinimumNumberShouldMatch(), greaterThan(0)); } } else if (queryBuilder.fields().size() == 1) {