|
@@ -1016,6 +1016,59 @@ public class SearchQueryIT extends ESIntegTestCase {
|
|
|
searchResponse = client().prepareSearch().setQuery(multiMatchQuery).get();
|
|
|
assertHitCount(searchResponse, 1l);
|
|
|
assertFirstHit(searchResponse, hasId("1"));
|
|
|
+ // Min should match > # optional clauses returns no docs.
|
|
|
+ multiMatchQuery = multiMatchQuery("value1 value2 value3", "field1", "field2");
|
|
|
+ multiMatchQuery.minimumShouldMatch("4");
|
|
|
+ searchResponse = client().prepareSearch().setQuery(multiMatchQuery).get();
|
|
|
+ assertHitCount(searchResponse, 0l);
|
|
|
+ }
|
|
|
+
|
|
|
+ public void testBoolQueryMinShouldMatchBiggerThanNumberOfShouldClauses() throws IOException {
|
|
|
+ createIndex("test");
|
|
|
+ client().prepareIndex("test", "type1", "1").setSource("field1", new String[]{"value1", "value2", "value3"}).get();
|
|
|
+ client().prepareIndex("test", "type1", "2").setSource("field2", "value1").get();
|
|
|
+ refresh();
|
|
|
+
|
|
|
+ BoolQueryBuilder boolQuery = boolQuery()
|
|
|
+ .must(termQuery("field1", "value1"))
|
|
|
+ .should(boolQuery()
|
|
|
+ .should(termQuery("field1", "value1"))
|
|
|
+ .should(termQuery("field1", "value2"))
|
|
|
+ .minimumNumberShouldMatch(3));
|
|
|
+ SearchResponse searchResponse = client().prepareSearch().setQuery(boolQuery).get();
|
|
|
+ assertHitCount(searchResponse, 1l);
|
|
|
+ assertFirstHit(searchResponse, hasId("1"));
|
|
|
+
|
|
|
+ boolQuery = boolQuery()
|
|
|
+ .must(termQuery("field1", "value1"))
|
|
|
+ .should(boolQuery()
|
|
|
+ .should(termQuery("field1", "value1"))
|
|
|
+ .should(termQuery("field1", "value2"))
|
|
|
+ .minimumNumberShouldMatch(1))
|
|
|
+ // Only one should clause is defined, returns no docs.
|
|
|
+ .minimumNumberShouldMatch(2);
|
|
|
+ searchResponse = client().prepareSearch().setQuery(boolQuery).get();
|
|
|
+ assertHitCount(searchResponse, 0l);
|
|
|
+
|
|
|
+ boolQuery = boolQuery()
|
|
|
+ .should(termQuery("field1", "value1"))
|
|
|
+ .should(boolQuery()
|
|
|
+ .should(termQuery("field1", "value1"))
|
|
|
+ .should(termQuery("field1", "value2"))
|
|
|
+ .minimumNumberShouldMatch(3))
|
|
|
+ .minimumNumberShouldMatch(1);
|
|
|
+ searchResponse = client().prepareSearch().setQuery(boolQuery).get();
|
|
|
+ assertHitCount(searchResponse, 1l);
|
|
|
+ assertFirstHit(searchResponse, hasId("1"));
|
|
|
+
|
|
|
+ boolQuery = boolQuery()
|
|
|
+ .must(termQuery("field1", "value1"))
|
|
|
+ .must(boolQuery()
|
|
|
+ .should(termQuery("field1", "value1"))
|
|
|
+ .should(termQuery("field1", "value2"))
|
|
|
+ .minimumNumberShouldMatch(3));
|
|
|
+ searchResponse = client().prepareSearch().setQuery(boolQuery).get();
|
|
|
+ assertHitCount(searchResponse, 0l);
|
|
|
}
|
|
|
|
|
|
public void testFuzzyQueryString() {
|