|
@@ -25,6 +25,7 @@ import org.apache.lucene.search.ConstantScoreQuery;
|
|
|
import org.apache.lucene.search.MatchAllDocsQuery;
|
|
|
import org.apache.lucene.search.Query;
|
|
|
import org.elasticsearch.common.ParseFieldMatcher;
|
|
|
+import org.elasticsearch.common.ParsingException;
|
|
|
import org.elasticsearch.common.bytes.BytesReference;
|
|
|
import org.elasticsearch.common.xcontent.XContentBuilder;
|
|
|
import org.elasticsearch.common.xcontent.XContentFactory;
|
|
@@ -370,6 +371,28 @@ public class BoolQueryBuilderTests extends AbstractQueryTestCase<BoolQueryBuilde
|
|
|
assertThat(ex.getMessage(), startsWith("query malformed, empty clause found at"));
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * test that unknown query names in the clauses throw an error
|
|
|
+ */
|
|
|
+ public void testUnknownQueryName() throws IOException {
|
|
|
+ String query = "{\"bool\" : {\"must\" : { \"unknown_query\" : { } } } }";
|
|
|
+
|
|
|
+ ParsingException ex = expectThrows(ParsingException.class, () -> parseQuery(query, ParseFieldMatcher.EMPTY));
|
|
|
+ assertEquals("no [query] registered for [unknown_query]", ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * test that two queries in object throws error
|
|
|
+ */
|
|
|
+ public void testTooManyQueriesInObject() throws IOException {
|
|
|
+ String clauseType = randomFrom(new String[] {"must", "should", "must_not", "filter"});
|
|
|
+ // should also throw error if invalid query is preceded by a valid one
|
|
|
+ String query = "{\"bool\" : {\"" + clauseType
|
|
|
+ + "\" : { \"match\" : { \"foo\" : \"bar\" } , \"match\" : { \"baz\" : \"buzz\" } } } }";
|
|
|
+ ParsingException ex = expectThrows(ParsingException.class, () -> parseQuery(query, ParseFieldMatcher.EMPTY));
|
|
|
+ assertEquals("expected [END_OBJECT] but got [FIELD_NAME], possibly too many query clauses", ex.getMessage());
|
|
|
+ }
|
|
|
+
|
|
|
public void testRewrite() throws IOException {
|
|
|
BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();
|
|
|
boolean mustRewrite = false;
|