Search in sources :

Example 21 with ParsingException

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

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

Example 22 with ParsingException

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

the class RangeQueryBuilderTests method testParseFailsWithMultipleFields.

public void testParseFailsWithMultipleFields() throws IOException {
    String json = "{\n" + "    \"range\": {\n" + "      \"age\": {\n" + "        \"gte\": 30,\n" + "        \"lte\": 40\n" + "      },\n" + "      \"price\": {\n" + "        \"gte\": 10,\n" + "        \"lte\": 30\n" + "      }\n" + "    }\n" + "  }";
    ParsingException e = expectThrows(ParsingException.class, () -> parseQuery(json));
    assertEquals("[range] query doesn't support multiple fields, found [age] and [price]", e.getMessage());
}
Also used : ParsingException(org.elasticsearch.common.ParsingException) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 23 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 24 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 25 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)

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