{"record":{"id":"9cb62be62469374c","repo":"elastic/elasticsearch","slug":"name-failed-to-parse-field-field","errorCode":null,"errorMessage":"[{name}] failed to parse field [{field}]","messagePattern":"\\[(.+?)\\] failed to parse field \\[(.+?)\\]","errorType":"exception","errorClass":"XContentParseException","httpStatus":null,"severity":"error","filePath":"libs/x-content/src/main/java/org/elasticsearch/xcontent/ConstructingObjectParser.java","lineNumber":444,"sourceCode":"    private <T> BiConsumer<Target, T> queueingConsumer(BiConsumer<Value, T> consumer, ParseField parseField) {\n        return (target, v) -> {\n            if (target.targetObject != null) {\n                // The target has already been built. Just apply the consumer now.\n                consumer.accept(target.targetObject, v);\n                return;\n            }\n            /*\n             * The target hasn't been built. Queue the consumer. The next two lines are the only allocations that ConstructingObjectParser\n             * does during parsing other than the boxing the ObjectParser might do. The first one is to preserve a snapshot of the current\n             * location so we can add it to the error message if parsing fails. The second one (the lambda) is the actual operation being\n             * queued. Note that we don't do any of this if the target object has already been built.\n             */\n            XContentLocation location = target.parser.getTokenLocation();\n            target.queue(targetObject -> {\n                try {\n                    consumer.accept(targetObject, v);\n                } catch (Exception e) {\n                    throw new XContentParseException(\n                        location,\n                        \"[\" + objectParser.getName() + \"] failed to parse field [\" + parseField.getPreferredName() + \"]\",\n                        e\n                    );\n                }\n            });\n        };\n    }\n\n    /**\n     * The target of the {@linkplain ConstructingObjectParser}. One of these is built every time you call\n     * {@linkplain ConstructingObjectParser#apply(XContentParser, Object)} Note that it is not static so it inherits\n     * {@linkplain ConstructingObjectParser}'s type parameters.\n     */\n    private class Target {\n        /**\n         * Array of constructor args to be passed to the {@link ConstructingObjectParser#builder}.\n         */","sourceCodeStart":426,"sourceCodeEnd":462,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/libs/x-content/src/main/java/org/elasticsearch/xcontent/ConstructingObjectParser.java#L426-L462","documentation":"When a declared field's value is parsed, ConstructingObjectParser queues a consumer; executing that consumer can throw if the value cannot be applied (type mismatch, range error, sub-object parse failure). The catch re-wraps into XContentParseException carrying the field's saved XContentLocation and the parser name, naming the offending field. This localizes the failure to a specific field rather than the whole object.","triggerScenarios":"A declared field receives a value of the wrong type (e.g. string where a number is declared), an enum that doesn't match, an object that fails its own sub-parser, or a value that violates a constraint checked inside the BiConsumer. Field-level parsing of any declared non-constructor field that throws.","commonSituations":"REST API requests with a field of the wrong JSON type. Aggregation/query body parsing where a sub-object is malformed. Version mismatches where a field's accepted shape changed.","solutions":["Use the named field in the message to locate the offending key, then correct its value type in the request to match the declared ValueType.","Inspect the cause for the precise conversion failure (NumberFormatException, sub-parse error) and address that specifically.","If the field is legitimately polymorphic, declare it with the correct ValueType or a custom ContextParser that tolerates the shapes you send."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    Value v = cop.parse(parser, ctx);\n} catch (XContentParseException e) {\n    if (e.getMessage().contains(\"failed to parse field [\")) {\n        String field = /* extract from message */;\n        // surface field-specific error to the caller/client\n    }\n}","preventionTips":["Declare each field with the ValueType matching the JSON shapes clients send.","Validate request field types at the REST boundary with a schema before reaching the parser.","Keep ParseField alias lists current so renames don't silently break field population."],"tags":["xcontent","constructing-object-parser","field-parse","deserialization"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}