use of org.elasticsearch.common.ParsingException in project elasticsearch by elastic.
the class StoredScriptTests method testSourceParsingErrors.
public void testSourceParsingErrors() throws Exception {
// check for missing lang parameter when parsing a template
try (XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON)) {
builder.startObject().field("template", "code").endObject();
IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> StoredScriptSource.parse(null, builder.bytes(), XContentType.JSON));
assertThat(iae.getMessage(), equalTo("unexpected stored script format"));
}
// check for missing lang parameter when parsing a script
try (XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON)) {
builder.startObject().field("script").startObject().field("code", "code").endObject().endObject();
IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> StoredScriptSource.parse(null, builder.bytes(), XContentType.JSON));
assertThat(iae.getMessage(), equalTo("must specify lang for stored script"));
}
// check for missing code parameter when parsing a script
try (XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON)) {
builder.startObject().field("script").startObject().field("lang", "lang").endObject().endObject();
IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> StoredScriptSource.parse(null, builder.bytes(), XContentType.JSON));
assertThat(iae.getMessage(), equalTo("must specify code for stored script"));
}
// check for illegal options parameter when parsing a script
try (XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON)) {
builder.startObject().field("script").startObject().field("lang", "lang").field("code", "code").startObject("options").field("option", "option").endObject().endObject().endObject();
IllegalArgumentException iae = expectThrows(IllegalArgumentException.class, () -> StoredScriptSource.parse(null, builder.bytes(), XContentType.JSON));
assertThat(iae.getMessage(), equalTo("illegal compiler options [{option=option}] specified"));
}
// check for illegal use of content type option
try (XContentBuilder builder = XContentFactory.contentBuilder(XContentType.JSON)) {
builder.startObject().field("script").startObject().field("lang", "lang").field("code", "code").startObject("options").field("content_type", "option").endObject().endObject().endObject();
ParsingException pe = expectThrows(ParsingException.class, () -> StoredScriptSource.parse(null, builder.bytes(), XContentType.JSON));
assertThat(pe.getRootCause().getMessage(), equalTo("content_type cannot be user-specified"));
}
}
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());
}
Aggregations