use of org.opensearch.common.ParsingException in project OpenSearch by opensearch-project.
the class MatchPhrasePrefixQueryBuilderTests method testParseFailsWithMultipleFields.
public void testParseFailsWithMultipleFields() throws IOException {
String json = "{\n" + " \"match_phrase_prefix\" : {\n" + " \"message1\" : {\n" + " \"query\" : \"this is a test\"\n" + " },\n" + " \"message2\" : {\n" + " \"query\" : \"this is a test\"\n" + " }\n" + " }\n" + "}";
ParsingException e = expectThrows(ParsingException.class, () -> parseQuery(json));
assertEquals("[match_phrase_prefix] query doesn't support multiple fields, found [message1] and [message2]", e.getMessage());
String shortJson = "{\n" + " \"match_phrase_prefix\" : {\n" + " \"message1\" : \"this is a test\",\n" + " \"message2\" : \"this is a test\"\n" + " }\n" + "}";
e = expectThrows(ParsingException.class, () -> parseQuery(shortJson));
assertEquals("[match_phrase_prefix] query doesn't support multiple fields, found [message1] and [message2]", e.getMessage());
}
use of org.opensearch.common.ParsingException in project OpenSearch by opensearch-project.
the class CommonTermsQueryBuilderTests method testParseFailsWithMultipleFields.
public void testParseFailsWithMultipleFields() throws IOException {
String json = "{\n" + " \"common\" : {\n" + " \"message1\" : {\n" + " \"query\" : \"nelly the elephant not as a cartoon\"\n" + " },\n" + " \"message2\" : {\n" + " \"query\" : \"nelly the elephant not as a cartoon\"\n" + " }\n" + " }\n" + "}";
ParsingException e = expectThrows(ParsingException.class, () -> parseQuery(json));
assertEquals("[common] query doesn't support multiple fields, found [message1] and [message2]", e.getMessage());
String shortJson = "{\n" + " \"common\" : {\n" + " \"message1\" : \"nelly the elephant not as a cartoon\",\n" + " \"message2\" : \"nelly the elephant not as a cartoon\"\n" + " }\n" + "}";
e = expectThrows(ParsingException.class, () -> parseQuery(shortJson));
assertEquals("[common] query doesn't support multiple fields, found [message1] and [message2]", e.getMessage());
assertDeprecationWarning();
}
use of org.opensearch.common.ParsingException in project OpenSearch by opensearch-project.
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.opensearch.common.ParsingException in project OpenSearch by opensearch-project.
the class ConstantScoreQueryBuilderTests method testFilterElement.
/**
* test that missing "filter" element causes {@link ParsingException}
*/
public void testFilterElement() throws IOException {
String queryString = "{ \"" + ConstantScoreQueryBuilder.NAME + "\" : {} }";
ParsingException e = expectThrows(ParsingException.class, () -> parseQuery(queryString));
assertThat(e.getMessage(), containsString("requires a 'filter' element"));
}
use of org.opensearch.common.ParsingException in project OpenSearch by opensearch-project.
the class IntervalQueryBuilderTests method testMultipleProviders.
public void testMultipleProviders() {
String json = "{ \"intervals\" : { \"" + TEXT_FIELD_NAME + "\": { " + "\"boost\" : 1," + "\"match\" : { \"query\" : \"term1\" }," + "\"all_of\" : { \"intervals\" : [ { \"query\" : \"term2\" } ] } }";
ParsingException e = expectThrows(ParsingException.class, () -> {
parseQuery(json);
});
assertThat(e.getMessage(), equalTo("Only one interval rule can be specified, found [match] and [all_of]"));
}
Aggregations