Search in sources :

Example 21 with ParsingException

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());
}
Also used : ParsingException(org.opensearch.common.ParsingException) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 22 with ParsingException

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]."));
}
Also used : ParsingException(org.opensearch.common.ParsingException) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 23 with ParsingException

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."));
}
Also used : ParsingException(org.opensearch.common.ParsingException) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 24 with ParsingException

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());
}
Also used : ParsingException(org.opensearch.common.ParsingException)

Example 25 with ParsingException

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());
}
Also used : ParsingException(org.opensearch.common.ParsingException)

Aggregations

ParsingException (org.opensearch.common.ParsingException)157 XContentParser (org.opensearch.common.xcontent.XContentParser)92 ArrayList (java.util.ArrayList)27 Matchers.containsString (org.hamcrest.Matchers.containsString)21 IOException (java.io.IOException)14 Token (org.opensearch.common.xcontent.XContentParser.Token)11 List (java.util.List)10 ShardId (org.opensearch.index.shard.ShardId)10 SearchShardTarget (org.opensearch.search.SearchShardTarget)10 BytesReference (org.opensearch.common.bytes.BytesReference)9 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)9 HashMap (java.util.HashMap)7 QueryBuilder (org.opensearch.index.query.QueryBuilder)7 ShardSearchFailure (org.opensearch.action.search.ShardSearchFailure)6 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)5 OpenSearchParseException (org.opensearch.OpenSearchParseException)5 TimestampParsingException (org.opensearch.action.TimestampParsingException)5 XContentLocation (org.opensearch.common.xcontent.XContentLocation)5 Script (org.opensearch.script.Script)5 GapPolicy (org.opensearch.search.aggregations.pipeline.BucketHelpers.GapPolicy)5