{"record":{"id":"fe074b2d3597b0c4","repo":"elastic/elasticsearch","slug":"failed-to-parse-field","errorCode":null,"errorMessage":"[{}] failed to parse field [{}]","messagePattern":"\\[(.+?)\\] failed to parse field \\[(.+?)\\]","errorType":"exception","errorClass":"XContentParseException","httpStatus":null,"severity":"error","filePath":"libs/x-content/src/main/java/org/elasticsearch/xcontent/ObjectParser.java","lineNumber":620,"sourceCode":"        }\n        this.exclusiveFieldSets.add(exclusiveSet);\n    }\n\n    private void parseArray(XContentParser parser, FieldParser fieldParser, String currentFieldName, Value value, Context context) {\n        assert parser.currentToken() == XContentParser.Token.START_ARRAY : \"Token was: \" + parser.currentToken();\n        parseValue(parser, fieldParser, currentFieldName, value, context);\n    }\n\n    private void parseValue(XContentParser parser, FieldParser fieldParser, String currentFieldName, Value value, Context context) {\n        try {\n            fieldParser.parser.parse(parser, value, context);\n        } catch (Exception ex) {\n            throwFailedToParse(parser, currentFieldName, ex);\n        }\n    }\n\n    private void throwFailedToParse(XContentParser parser, String currentFieldName, Exception ex) {\n        throw new XContentParseException(parser.getTokenLocation(), \"[\" + name + \"] failed to parse field [\" + currentFieldName + \"]\", ex);\n    }\n\n    private void parseSub(\n        XContentParser parser,\n        FieldParser fieldParser,\n        XContentParser.Token token,\n        String currentFieldName,\n        Value value,\n        Context context\n    ) {\n        switch (token) {\n            case START_OBJECT -> {\n                parseValue(parser, fieldParser, currentFieldName, value, context);\n                /*\n                 * Well behaving parsers should consume the entire object but\n                 * asserting that they do that is not something we can do\n                 * efficiently here. Instead we can check that they end on an\n                 * END_OBJECT. They could end on the *wrong* end object and","sourceCodeStart":602,"sourceCodeEnd":638,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/libs/x-content/src/main/java/org/elasticsearch/xcontent/ObjectParser.java#L602-L638","documentation":"Thrown by throwFailedToParse when the FieldParser's parse callback throws any Exception while consuming a field's value. This is a general-purpose wrapper that adds location (token location) and field-name context to whatever underlying parsing error occurred, making it easier to identify which field caused the failure.","triggerScenarios":"Any field-level parsing failure: a number field receiving a non-numeric string, an enum field receiving an unrecognized constant, a nested object field receiving malformed sub-object content, a date field with an unparseable format string, etc. The original exception is preserved as the cause.","commonSituations":"Providing the wrong data type for a declared field. Sending a date in a format not matching the declared format pattern. Sending a string where a number is expected (with coercion disabled). Nesting errors in sub-objects that propagate up.","solutions":["Inspect the cause exception for the specific field-level error type and message.","Verify the field value matches the expected type declared in the mapping or API spec.","If the cause is a number/date/format error, apply the fix for that specific underlying error.","Check the field name in the error message to locate the problematic key in the request."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Before sending, validate each field value type against the expected schema\nMap<String, Class<?>> schema = Map.of(\"size\", Integer.class, \"name\", String.class);\nfor (Map.Entry<String, Object> entry : body.entrySet()) {\n    Class<?> expected = schema.get(entry.getKey());\n    if (expected != null && !expected.isInstance(entry.getValue())) {\n        throw new IllegalArgumentException(entry.getKey() + \" expects \" + expected.getSimpleName());\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    objectParser.parse(parser, context);\n} catch (XContentParseException e) {\n    if (e.getMessage().contains(\"failed to parse field\")) {\n        String fieldName = extractFieldName(e.getMessage());\n        logger.warn(\"Field [{}] failed to parse: {}\", fieldName, e.getCause().getMessage());\n        return badRequest(\"Invalid value for field: \" + fieldName);\n    }\n    throw e;\n}","preventionTips":["Validate field value types against the mapping schema before sending.","Use typed client DTOs that enforce correct field types at compile time.","Inspect the cause exception chain for the specific field-level error type.","Write unit tests that send intentionally wrong types to verify error messages."],"tags":["parsing","xcontent","field-error","object-parser"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}