Search in sources :

Example 76 with ParsingException

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

the class SignificanceHeuristicTests method checkParseException.

protected void checkParseException(ParseFieldRegistry<SignificanceHeuristicParser> significanceHeuristicParserRegistry, String faultyHeuristicDefinition, String expectedError) throws IOException {
    try {
        XContentParser stParser = createParser(JsonXContent.jsonXContent, "{\"field\":\"text\", " + faultyHeuristicDefinition + ",\"min_doc_count\":200}");
        QueryParseContext parseContext = new QueryParseContext(stParser);
        stParser.nextToken();
        SignificantTermsAggregationBuilder.getParser(significanceHeuristicParserRegistry).parse("testagg", parseContext);
        fail();
    } catch (ParsingException e) {
        assertThat(e.getCause().getMessage(), containsString(expectedError));
    }
}
Also used : QueryParseContext(org.elasticsearch.index.query.QueryParseContext) ParsingException(org.elasticsearch.common.ParsingException) XContentParser(org.elasticsearch.common.xcontent.XContentParser)

Example 77 with ParsingException

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

the class SearchSourceBuilderTests method assertIndicesBoostParseErrorMessage.

private void assertIndicesBoostParseErrorMessage(String restContent, String expectedErrorMessage) throws IOException {
    try (XContentParser parser = createParser(JsonXContent.jsonXContent, restContent)) {
        ParsingException e = expectThrows(ParsingException.class, () -> SearchSourceBuilder.fromXContent(createParseContext(parser)));
        assertEquals(expectedErrorMessage, e.getMessage());
    }
}
Also used : ParsingException(org.elasticsearch.common.ParsingException) XContentParser(org.elasticsearch.common.xcontent.XContentParser)

Example 78 with ParsingException

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

the class SearchSourceBuilderTests method testMultipleQueryObjectsAreRejected.

public void testMultipleQueryObjectsAreRejected() throws Exception {
    String restContent = " { \"query\": {\n" + "    \"multi_match\": {\n" + "      \"query\": \"workd\",\n" + "      \"fields\": [\"title^5\", \"plain_body\"]\n" + "    },\n" + "    \"filters\": {\n" + "      \"terms\": {\n" + "        \"status\": [ 3 ]\n" + "      }\n" + "    }\n" + "  } }";
    try (XContentParser parser = createParser(JsonXContent.jsonXContent, restContent)) {
        ParsingException e = expectThrows(ParsingException.class, () -> SearchSourceBuilder.fromXContent(createParseContext(parser)));
        assertEquals("[multi_match] malformed query, expected [END_OBJECT] but found [FIELD_NAME]", e.getMessage());
    }
}
Also used : ParsingException(org.elasticsearch.common.ParsingException) Matchers.hasToString(org.hamcrest.Matchers.hasToString) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) XContentParser(org.elasticsearch.common.xcontent.XContentParser)

Example 79 with ParsingException

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

the class HighlightBuilderTests method testTwoFieldsInObjectInFieldsArray.

public void testTwoFieldsInObjectInFieldsArray() throws IOException {
    ParsingException e = expectParseThrows(ParsingException.class, "{\n" + "  \"fields\" : [ {\n" + "     \"body\" : {},\n" + "     \"nope\" : {}\n" + "   }] \n" + "}\n");
    assertEquals("[highlight] failed to parse field [fields]", e.getMessage());
    assertEquals("[fields] can be a single object with any number of fields or an array where each entry is an object with a single field", e.getCause().getMessage());
}
Also used : ParsingException(org.elasticsearch.common.ParsingException)

Example 80 with ParsingException

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

the class HighlightBuilderTests method testParsingTagsSchema.

/**
     * `tags_schema` is not produced by toXContent in the builder but should be parseable, so this
     * adds a simple json test for this.
     */
public void testParsingTagsSchema() throws IOException {
    String highlightElement = "{\n" + "    \"tags_schema\" : \"styled\"\n" + "}\n";
    XContentParser parser = createParser(JsonXContent.jsonXContent, highlightElement);
    QueryParseContext context = new QueryParseContext(parser);
    HighlightBuilder highlightBuilder = HighlightBuilder.fromXContent(context);
    assertArrayEquals("setting tags_schema 'styled' should alter pre_tags", HighlightBuilder.DEFAULT_STYLED_PRE_TAG, highlightBuilder.preTags());
    assertArrayEquals("setting tags_schema 'styled' should alter post_tags", HighlightBuilder.DEFAULT_STYLED_POST_TAGS, highlightBuilder.postTags());
    highlightElement = "{\n" + "    \"tags_schema\" : \"default\"\n" + "}\n";
    parser = createParser(JsonXContent.jsonXContent, highlightElement);
    context = new QueryParseContext(parser);
    highlightBuilder = HighlightBuilder.fromXContent(context);
    assertArrayEquals("setting tags_schema 'default' should alter pre_tags", HighlightBuilder.DEFAULT_PRE_TAGS, highlightBuilder.preTags());
    assertArrayEquals("setting tags_schema 'default' should alter post_tags", HighlightBuilder.DEFAULT_POST_TAGS, highlightBuilder.postTags());
    ParsingException e = expectParseThrows(ParsingException.class, "{\n" + "    \"tags_schema\" : \"somthing_else\"\n" + "}\n");
    assertEquals("[highlight] failed to parse field [tags_schema]", e.getMessage());
    assertEquals("Unknown tag schema [somthing_else]", e.getCause().getMessage());
}
Also used : QueryParseContext(org.elasticsearch.index.query.QueryParseContext) ParsingException(org.elasticsearch.common.ParsingException) XContentParser(org.elasticsearch.common.xcontent.XContentParser)

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