use of org.elasticsearch.common.ParsingException in project elasticsearch by elastic.
the class ConstantScoreQueryBuilderTests method testNoArrayAsFilterElements.
/**
* test that "filter" does not accept an array of queries, throws {@link ParsingException}
*/
public void testNoArrayAsFilterElements() throws IOException {
String queryString = "{ \"" + ConstantScoreQueryBuilder.NAME + "\" : {\n" + "\"filter\" : [ { \"term\": { \"foo\": \"a\" } },\n" + "{ \"term\": { \"foo\": \"x\" } } ]\n" + "} }";
ParsingException e = expectThrows(ParsingException.class, () -> parseQuery(queryString));
assertThat(e.getMessage(), containsString("unexpected token [START_ARRAY]"));
}
use of org.elasticsearch.common.ParsingException in project elasticsearch by elastic.
the class FuzzyQueryBuilderTests method testParseFailsWithMultipleFields.
public void testParseFailsWithMultipleFields() throws IOException {
String json1 = "{\n" + " \"fuzzy\" : {\n" + " \"message1\" : {\n" + " \"value\" : \"this is a test\"\n" + " }\n" + " }\n" + "}";
// should be all good
parseQuery(json1);
String json2 = "{\n" + " \"fuzzy\" : {\n" + " \"message1\" : {\n" + " \"value\" : \"this is a test\"\n" + " },\n" + " \"message2\" : {\n" + " \"value\" : \"this is a test\"\n" + " }\n" + " }\n" + "}";
ParsingException e = expectThrows(ParsingException.class, () -> parseQuery(json2));
assertEquals("[fuzzy] query doesn't support multiple fields, found [message1] and [message2]", e.getMessage());
String shortJson = "{\n" + " \"fuzzy\" : {\n" + " \"message1\" : \"this is a test\",\n" + " \"message2\" : \"value\" : \"this is a test\"\n" + " }\n" + "}";
e = expectThrows(ParsingException.class, () -> parseQuery(shortJson));
assertEquals("[fuzzy] query doesn't support multiple fields, found [message1] and [message2]", e.getMessage());
}
use of org.elasticsearch.common.ParsingException in project elasticsearch by elastic.
the class BoolQueryBuilderTests method testTooManyQueriesInObject.
/**
* test that two queries in object throws error
*/
public void testTooManyQueriesInObject() throws IOException {
assumeFalse("Test only makes sense if XContent parser doesn't have strict duplicate checks enabled", XContent.isStrictDuplicateDetectionEnabled());
String clauseType = randomFrom("must", "should", "must_not", "filter");
// should also throw error if invalid query is preceded by a valid one
String query = "{\n" + " \"bool\": {\n" + " \"" + clauseType + "\": {\n" + " \"match\": {\n" + " \"foo\": \"bar\"\n" + " },\n" + " \"match\": {\n" + " \"baz\": \"buzz\"\n" + " }\n" + " }\n" + " }\n" + "}";
ParsingException ex = expectThrows(ParsingException.class, () -> parseQuery(query));
assertEquals("[match] malformed query, expected [END_OBJECT] but found [FIELD_NAME]", ex.getMessage());
}
use of org.elasticsearch.common.ParsingException in project elasticsearch by elastic.
the class QueryStringQueryBuilderTests method testAllFieldsWithFields.
public void testAllFieldsWithFields() throws IOException {
String json = "{\n" + " \"query_string\" : {\n" + " \"query\" : \"this AND that OR thus\",\n" + " \"fields\" : [\"foo\"],\n" + " \"all_fields\" : true\n" + " }\n" + "}";
ParsingException e = expectThrows(ParsingException.class, () -> parseQuery(json));
assertThat(e.getMessage(), containsString("cannot use [all_fields] parameter in conjunction with [default_field] or [fields]"));
String json2 = "{\n" + " \"query_string\" : {\n" + " \"query\" : \"this AND that OR thus\",\n" + " \"default_field\" : \"foo\",\n" + " \"all_fields\" : true\n" + " }\n" + "}";
e = expectThrows(ParsingException.class, () -> parseQuery(json2));
assertThat(e.getMessage(), containsString("cannot use [all_fields] parameter in conjunction with [default_field] or [fields]"));
}
use of org.elasticsearch.common.ParsingException in project elasticsearch by elastic.
the class QueryParseContextTests method testParseInnerQueryBuilderExceptions.
public void testParseInnerQueryBuilderExceptions() throws IOException {
String source = "{ \"foo\": \"bar\" }";
try (XContentParser parser = createParser(JsonXContent.jsonXContent, source)) {
parser.nextToken();
// don't start with START_OBJECT to provoke exception
parser.nextToken();
QueryParseContext context = new QueryParseContext(parser);
ParsingException exception = expectThrows(ParsingException.class, () -> context.parseInnerQueryBuilder());
assertEquals("[_na] query malformed, must start with start_object", exception.getMessage());
}
source = "{}";
try (XContentParser parser = createParser(JsonXContent.jsonXContent, source)) {
QueryParseContext context = new QueryParseContext(parser);
IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () -> context.parseInnerQueryBuilder());
assertEquals("query malformed, empty clause found at [1:2]", exception.getMessage());
}
source = "{ \"foo\" : \"bar\" }";
try (XContentParser parser = createParser(JsonXContent.jsonXContent, source)) {
QueryParseContext context = new QueryParseContext(parser);
ParsingException exception = expectThrows(ParsingException.class, () -> context.parseInnerQueryBuilder());
assertEquals("[foo] query malformed, no start_object after query name", exception.getMessage());
}
source = "{ \"foo\" : {} }";
try (XContentParser parser = createParser(JsonXContent.jsonXContent, source)) {
QueryParseContext context = new QueryParseContext(parser);
ParsingException exception = expectThrows(ParsingException.class, () -> context.parseInnerQueryBuilder());
assertEquals("no [query] registered for [foo]", exception.getMessage());
}
}
Aggregations