use of org.opensearch.common.xcontent.XContentParseException in project OpenSearch by opensearch-project.
the class GeoHashGridParserTests method testParseErrorOnBooleanPrecision.
public void testParseErrorOnBooleanPrecision() throws Exception {
XContentParser stParser = createParser(JsonXContent.jsonXContent, "{\"field\":\"my_loc\", \"precision\":false}");
XContentParser.Token token = stParser.nextToken();
assertSame(XContentParser.Token.START_OBJECT, token);
XContentParseException e = expectThrows(XContentParseException.class, () -> GeoHashGridAggregationBuilder.PARSER.parse(stParser, "geohash_grid"));
assertThat(e.getMessage(), containsString("[geohash_grid] precision doesn't support values of type: VALUE_BOOLEAN"));
}
use of org.opensearch.common.xcontent.XContentParseException in project OpenSearch by opensearch-project.
the class GeoHashGridParserTests method testParseInvalidUnitPrecision.
public void testParseInvalidUnitPrecision() throws Exception {
XContentParser stParser = createParser(JsonXContent.jsonXContent, "{\"field\":\"my_loc\", \"precision\": \"10kg\", \"size\": \"500\", \"shard_size\": \"550\"}");
XContentParser.Token token = stParser.nextToken();
assertSame(XContentParser.Token.START_OBJECT, token);
XContentParseException ex = expectThrows(XContentParseException.class, () -> GeoHashGridAggregationBuilder.PARSER.parse(stParser, "geohash_grid"));
assertThat(ex.getMessage(), containsString("[geohash_grid] failed to parse field [precision]"));
assertThat(ex.getCause(), instanceOf(NumberFormatException.class));
assertEquals("For input string: \"10kg\"", ex.getCause().getMessage());
}
use of org.opensearch.common.xcontent.XContentParseException in project OpenSearch by opensearch-project.
the class GeoTileGridParserTests method testParseErrorOnPrecisionOutOfRange.
public void testParseErrorOnPrecisionOutOfRange() throws Exception {
XContentParser stParser = createParser(JsonXContent.jsonXContent, "{\"field\":\"my_loc\", \"precision\":\"30\"}");
XContentParser.Token token = stParser.nextToken();
assertSame(XContentParser.Token.START_OBJECT, token);
try {
GeoTileGridAggregationBuilder.PARSER.parse(stParser, "geotile_grid");
fail();
} catch (XContentParseException ex) {
assertThat(ex.getCause(), instanceOf(IllegalArgumentException.class));
assertEquals("Invalid geotile_grid precision of 30. Must be between 0 and 29.", ex.getCause().getMessage());
}
}
use of org.opensearch.common.xcontent.XContentParseException in project OpenSearch by opensearch-project.
the class PercentilesTests method testExceptionMultipleMethods.
public void testExceptionMultipleMethods() throws IOException {
final String illegalAgg = "{\n" + " \"percentiles\": {\n" + " \"field\": \"load_time\",\n" + " \"percents\": [99],\n" + " \"tdigest\": {\n" + " \"compression\": 200\n" + " },\n" + " \"hdr\": {\n" + " \"number_of_significant_value_digits\": 3\n" + " }\n" + " }\n" + "}";
XContentParser parser = createParser(JsonXContent.jsonXContent, illegalAgg);
assertEquals(XContentParser.Token.START_OBJECT, parser.nextToken());
assertEquals(XContentParser.Token.FIELD_NAME, parser.nextToken());
XContentParseException e = expectThrows(XContentParseException.class, () -> PercentilesAggregationBuilder.parse("myPercentiles", parser));
assertThat(e.getMessage(), containsString("[percentiles] failed to parse field [hdr]"));
}
use of org.opensearch.common.xcontent.XContentParseException in project OpenSearch by opensearch-project.
the class UpdateRequestTests method testUnknownFieldParsing.
public void testUnknownFieldParsing() throws Exception {
UpdateRequest request = new UpdateRequest("test", "1");
XContentParser contentParser = createParser(XContentFactory.jsonBuilder().startObject().field("unknown_field", "test").endObject());
XContentParseException ex = expectThrows(XContentParseException.class, () -> request.fromXContent(contentParser));
assertEquals("[1:2] [UpdateRequest] unknown field [unknown_field]", ex.getMessage());
UpdateRequest request2 = new UpdateRequest("test", "1");
XContentParser unknownObject = createParser(XContentFactory.jsonBuilder().startObject().field("script", "ctx.op = ctx._source.views == params.count ? 'delete' : 'none'").startObject("params").field("count", 1).endObject().endObject());
ex = expectThrows(XContentParseException.class, () -> request2.fromXContent(unknownObject));
assertEquals("[1:76] [UpdateRequest] unknown field [params]", ex.getMessage());
}
Aggregations