Search in sources :

Example 16 with XContentParseException

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"));
}
Also used : XContentParser(org.opensearch.common.xcontent.XContentParser) XContentParseException(org.opensearch.common.xcontent.XContentParseException)

Example 17 with XContentParseException

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());
}
Also used : XContentParser(org.opensearch.common.xcontent.XContentParser) XContentParseException(org.opensearch.common.xcontent.XContentParseException)

Example 18 with XContentParseException

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());
    }
}
Also used : XContentParser(org.opensearch.common.xcontent.XContentParser) XContentParseException(org.opensearch.common.xcontent.XContentParseException)

Example 19 with XContentParseException

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]"));
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) XContentParser(org.opensearch.common.xcontent.XContentParser) XContentParseException(org.opensearch.common.xcontent.XContentParseException)

Example 20 with XContentParseException

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());
}
Also used : XContentParser(org.opensearch.common.xcontent.XContentParser) XContentParseException(org.opensearch.common.xcontent.XContentParseException)

Aggregations

XContentParseException (org.opensearch.common.xcontent.XContentParseException)41 XContentParser (org.opensearch.common.xcontent.XContentParser)32 Matchers.containsString (org.hamcrest.Matchers.containsString)11 XContentType (org.opensearch.common.xcontent.XContentType)8 BytesReference (org.opensearch.common.bytes.BytesReference)7 XContentBuilder (org.opensearch.common.xcontent.XContentBuilder)5 ParsingException (org.opensearch.common.ParsingException)4 CategoryContextMapping (org.opensearch.search.suggest.completion.context.CategoryContextMapping)4 IOException (java.io.IOException)3 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)2 HasAttributeNodeSelector (org.opensearch.client.HasAttributeNodeSelector)2 Node (org.opensearch.client.Node)2 NodeSelector (org.opensearch.client.NodeSelector)2 InputStream (java.io.InputStream)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 ContentTooLongException (org.apache.http.ContentTooLongException)1 HttpEntity (org.apache.http.HttpEntity)1 LegacyESVersion (org.opensearch.LegacyESVersion)1