Search in sources :

Example 11 with ParsingException

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

Example 12 with ParsingException

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

Example 13 with ParsingException

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

Example 14 with ParsingException

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

Example 15 with ParsingException

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]"));
}
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