Search in sources :

Example 66 with ParsingException

use of org.elasticsearch.common.ParsingException in project elasticsearch by elastic.

the class WildcardQueryBuilderTests method testParseFailsWithMultipleFields.

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

Example 67 with ParsingException

use of org.elasticsearch.common.ParsingException in project elasticsearch by elastic.

the class FunctionScoreQueryBuilderTests method expectParsingException.

private void expectParsingException(String json, Matcher<String> messageMatcher) {
    ParsingException e = expectThrows(ParsingException.class, () -> parseQuery(json));
    assertThat(e.getMessage(), messageMatcher);
}
Also used : ParsingException(org.elasticsearch.common.ParsingException)

Example 68 with ParsingException

use of org.elasticsearch.common.ParsingException in project elasticsearch by elastic.

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.elasticsearch.common.ParsingException) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 69 with ParsingException

use of org.elasticsearch.common.ParsingException in project elasticsearch by elastic.

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.elasticsearch.common.ParsingException)

Example 70 with ParsingException

use of org.elasticsearch.common.ParsingException in project elasticsearch by elastic.

the class TermQueryBuilderTests method testTermArray.

public void testTermArray() throws IOException {
    String queryAsString = "{\n" + "    \"term\": {\n" + "        \"age\": [34, 35]\n" + "    }\n" + "}";
    ParsingException e = expectThrows(ParsingException.class, () -> parseQuery(queryAsString));
    assertEquals("[term] query does not support array of values", e.getMessage());
}
Also used : ParsingException(org.elasticsearch.common.ParsingException)

Aggregations

ParsingException (org.elasticsearch.common.ParsingException)165 XContentParser (org.elasticsearch.common.xcontent.XContentParser)96 ArrayList (java.util.ArrayList)26 Matchers.containsString (org.hamcrest.Matchers.containsString)22 IOException (java.io.IOException)12 HashMap (java.util.HashMap)10 Token (org.elasticsearch.common.xcontent.XContentParser.Token)9 XContentBuilder (org.elasticsearch.common.xcontent.XContentBuilder)7 Index (org.elasticsearch.index.Index)7 Script (org.elasticsearch.script.Script)7 SearchShardTarget (org.elasticsearch.search.SearchShardTarget)7 List (java.util.List)6 BytesReference (org.elasticsearch.common.bytes.BytesReference)6 QueryParseContext (org.elasticsearch.index.query.QueryParseContext)6 ElasticsearchParseException (org.elasticsearch.ElasticsearchParseException)5 GeoPoint (org.elasticsearch.common.geo.GeoPoint)5 GapPolicy (org.elasticsearch.search.aggregations.pipeline.BucketHelpers.GapPolicy)5 SearchPhaseExecutionException (org.elasticsearch.action.search.SearchPhaseExecutionException)4 ToXContent (org.elasticsearch.common.xcontent.ToXContent)4 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)4