use of org.opensearch.common.ParsingException in project OpenSearch by opensearch-project.
the class FuzzyQueryBuilderTests method testParseFailsWithValueArray.
public void testParseFailsWithValueArray() {
String query = "{\n" + " \"fuzzy\" : {\n" + " \"message1\" : {\n" + " \"value\" : [ \"one\", \"two\", \"three\"]\n" + " }\n" + " }\n" + "}";
ParsingException e = expectThrows(ParsingException.class, () -> parseQuery(query));
assertEquals("[fuzzy] unexpected token [START_ARRAY] after [value]", e.getMessage());
}
use of org.opensearch.common.ParsingException in project OpenSearch by opensearch-project.
the class FunctionScoreQueryBuilderTests method testProperErrorMessageWhenTwoFunctionsDefinedInFunctionsArray.
public void testProperErrorMessageWhenTwoFunctionsDefinedInFunctionsArray() throws IOException {
String functionScoreQuery = "{\n" + " \"function_score\":{\n" + " \"functions\": [\n" + " {\n" + " \"random_score\": {\n" + " \"seed\":123456\n" + " },\n" + " \"weight\": 3,\n" + " \"script_score\": {\n" + " \"script\": \"_index['text']['foo'].tf()\"\n" + " },\n" + " \"filter\": {\n" + " \"term\":{\n" + " \"field2\":\"value2\"\n" + " }\n" + " }\n" + " }\n" + " ]\n" + " }\n" + "}";
ParsingException e = expectThrows(ParsingException.class, () -> parseQuery(functionScoreQuery));
assertThat(e.getMessage(), containsString("failed to parse function_score functions. already found [random_score], now encountering [script_score]."));
}
use of org.opensearch.common.ParsingException in project OpenSearch by opensearch-project.
the class FunctionScoreQueryBuilderTests method testProperErrorMessageWhenMissingFunction.
public void testProperErrorMessageWhenMissingFunction() throws IOException {
String functionScoreQuery = "{\n" + " \"function_score\":{\n" + " \"functions\": [\n" + " {\n" + " \"filter\": {\n" + " \"term\":{\n" + " \"field2\":\"value2\"\n" + " }\n" + " }\n" + " }\n" + " ]\n" + " }\n" + "}";
ParsingException e = expectThrows(ParsingException.class, () -> parseQuery(functionScoreQuery));
assertThat(e.getMessage(), containsString("an entry in functions list is missing a function."));
}
use of org.opensearch.common.ParsingException in project OpenSearch by opensearch-project.
the class SpanTermQueryBuilderTests method testParseFailsWithMultipleFields.
public void testParseFailsWithMultipleFields() throws IOException {
String json = "{\n" + " \"span_term\" : {\n" + " \"message1\" : {\n" + " \"term\" : \"this\"\n" + " },\n" + " \"message2\" : {\n" + " \"term\" : \"this\"\n" + " }\n" + " }\n" + "}";
ParsingException e = expectThrows(ParsingException.class, () -> parseQuery(json));
assertEquals("[span_term] query doesn't support multiple fields, found [message1] and [message2]", e.getMessage());
String shortJson = "{\n" + " \"span_term\" : {\n" + " \"message1\" : \"this\",\n" + " \"message2\" : \"this\"\n" + " }\n" + "}";
e = expectThrows(ParsingException.class, () -> parseQuery(shortJson));
assertEquals("[span_term] 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 TermQueryBuilderTests method testParseFailsWithMultipleFields.
public void testParseFailsWithMultipleFields() throws IOException {
String json = "{\n" + " \"term\" : {\n" + " \"message1\" : {\n" + " \"value\" : \"this\"\n" + " },\n" + " \"message2\" : {\n" + " \"value\" : \"this\"\n" + " }\n" + " }\n" + "}";
ParsingException e = expectThrows(ParsingException.class, () -> parseQuery(json));
assertEquals("[term] query doesn't support multiple fields, found [message1] and [message2]", e.getMessage());
String shortJson = "{\n" + " \"term\" : {\n" + " \"message1\" : \"this\",\n" + " \"message2\" : \"this\"\n" + " }\n" + "}";
e = expectThrows(ParsingException.class, () -> parseQuery(shortJson));
assertEquals("[term] query doesn't support multiple fields, found [message1] and [message2]", e.getMessage());
}
Aggregations