Search in sources :

Example 16 with ParsingException

use of org.opensearch.common.ParsingException in project OpenSearch by opensearch-project.

the class MatchPhraseQueryBuilderTests method testParseFailsWithMultipleFields.

public void testParseFailsWithMultipleFields() throws IOException {
    String json = "{\n" + "  \"match_phrase\" : {\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] query doesn't support multiple fields, found [message1] and [message2]", e.getMessage());
    String shortJson = "{\n" + "  \"match_phrase\" : {\n" + "    \"message1\" : \"this is a test\",\n" + "    \"message2\" : \"this is a test\"\n" + "  }\n" + "}";
    e = expectThrows(ParsingException.class, () -> parseQuery(shortJson));
    assertEquals("[match_phrase] query doesn't support multiple fields, found [message1] and [message2]", e.getMessage());
}
Also used : ParsingException(org.opensearch.common.ParsingException) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 17 with ParsingException

use of org.opensearch.common.ParsingException in project OpenSearch by opensearch-project.

the class MultiMatchQueryBuilderTests method testQueryParameterArrayException.

public void testQueryParameterArrayException() {
    String json = "{\n" + "  \"multi_match\" : {\n" + "    \"query\" : [\"quick\", \"brown\", \"fox\"]\n" + "    \"fields\" : [ \"title^1.0\", \"title.original^1.0\", \"title.shingles^1.0\" ]" + "  }\n" + "}";
    ParsingException e = expectThrows(ParsingException.class, () -> parseQuery(json));
    assertEquals("[multi_match] unknown token [START_ARRAY] after [query]", e.getMessage());
}
Also used : ParsingException(org.opensearch.common.ParsingException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString)

Example 18 with ParsingException

use of org.opensearch.common.ParsingException in project OpenSearch by opensearch-project.

the class PrefixQueryBuilderTests method testParseFailsWithMultipleFields.

public void testParseFailsWithMultipleFields() throws IOException {
    String json = "{\n" + "    \"prefix\": {\n" + "      \"user1\": {\n" + "        \"value\": \"ki\"\n" + "      },\n" + "      \"user2\": {\n" + "        \"value\": \"ki\"\n" + "      }\n" + "    }\n" + "}";
    ParsingException e = expectThrows(ParsingException.class, () -> parseQuery(json));
    assertEquals("[prefix] query doesn't support multiple fields, found [user1] and [user2]", e.getMessage());
    String shortJson = "{\n" + "    \"prefix\": {\n" + "      \"user1\": \"ki\",\n" + "      \"user2\": \"ki\"\n" + "    }\n" + "}";
    e = expectThrows(ParsingException.class, () -> parseQuery(shortJson));
    assertEquals("[prefix] query doesn't support multiple fields, found [user1] and [user2]", e.getMessage());
}
Also used : ParsingException(org.opensearch.common.ParsingException)

Example 19 with ParsingException

use of org.opensearch.common.ParsingException in project OpenSearch by opensearch-project.

the class RegexpQueryBuilderTests method testParseFailsWithMultipleFields.

public void testParseFailsWithMultipleFields() throws IOException {
    String json = "{\n" + "    \"regexp\": {\n" + "      \"user1\": {\n" + "        \"value\": \"k.*y\"\n" + "      },\n" + "      \"user2\": {\n" + "        \"value\": \"k.*y\"\n" + "      }\n" + "    }\n" + "}";
    ParsingException e = expectThrows(ParsingException.class, () -> parseQuery(json));
    assertEquals("[regexp] query doesn't support multiple fields, found [user1] and [user2]", e.getMessage());
    String shortJson = "{\n" + "    \"regexp\": {\n" + "      \"user1\": \"k.*y\",\n" + "      \"user2\": \"k.*y\"\n" + "    }\n" + "}";
    e = expectThrows(ParsingException.class, () -> parseQuery(shortJson));
    assertEquals("[regexp] query doesn't support multiple fields, found [user1] and [user2]", e.getMessage());
}
Also used : ParsingException(org.opensearch.common.ParsingException)

Example 20 with ParsingException

use of org.opensearch.common.ParsingException in project OpenSearch by opensearch-project.

the class ScriptQueryBuilderTests method testArrayOfScriptsException.

public void testArrayOfScriptsException() {
    String json = "{\n" + "  \"script\" : {\n" + "    \"script\" : [ {\n" + "      \"source\" : \"5\",\n" + "      \"lang\" : \"mockscript\"\n" + "    },\n" + "    {\n" + "      \"source\" : \"6\",\n" + "      \"lang\" : \"mockscript\"\n" + "    }\n ]" + "  }\n" + "}";
    ParsingException e = expectThrows(ParsingException.class, () -> parseQuery(json));
    assertThat(e.getMessage(), containsString("does not support an array of scripts"));
}
Also used : ParsingException(org.opensearch.common.ParsingException) Matchers.containsString(org.hamcrest.Matchers.containsString)

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