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));
}
}
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());
}
}
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());
}
}
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());
}
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());
}
Aggregations