{"record":{"id":"c1dc409e897c378f","repo":"elastic/elasticsearch","slug":"unknown-field-c1dc40","errorCode":null,"errorMessage":"[{}] unknown field [{}]","messagePattern":"\\[(.+?)\\] unknown field \\[(.+?)\\]","errorType":"exception","errorClass":"XContentParseException","httpStatus":null,"severity":"error","filePath":"libs/x-content/src/main/java/org/elasticsearch/xcontent/ObjectParser.java","lineNumber":104,"sourceCode":"\n    private interface UnknownFieldParser<Value, Context> {\n        void acceptUnknownField(\n            ObjectParser<Value, Context> objectParser,\n            String field,\n            XContentLocation location,\n            XContentParser parser,\n            Value value,\n            Context context\n        ) throws IOException;\n    }\n\n    private static <Value, Context> UnknownFieldParser<Value, Context> ignoreUnknown() {\n        return (op, f, l, p, v, c) -> p.skipChildren();\n    }\n\n    private static <Value, Context> UnknownFieldParser<Value, Context> errorOnUnknown() {\n        return (op, f, l, p, v, c) -> {\n            throw new XContentParseException(\n                l,\n                ErrorOnUnknown.IMPLEMENTATION.errorMessage(\n                    op.name,\n                    f,\n                    op.fieldParserMap.getOrDefault(p.getRestApiVersion(), Collections.emptyMap()).keySet()\n                )\n            );\n        };\n    }\n\n    /**\n     * Defines how to consume a parsed undefined field\n     */\n    public interface UnknownFieldConsumer<Value> {\n        void accept(Value target, String field, Object value);\n    }\n\n    private static <Value, Context> UnknownFieldParser<Value, Context> consumeUnknownField(UnknownFieldConsumer<Value> consumer) {","sourceCodeStart":86,"sourceCodeEnd":122,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/libs/x-content/src/main/java/org/elasticsearch/xcontent/ObjectParser.java#L86-L122","documentation":"ObjectParser's errorOnUnknown strategy throws XContentParseException when input contains a field name not present in the parser's fieldParserMap for the active REST API version. The message lists the parser name, the offending field, and (via ErrorOnUnknown.IMPLEMENTATION) the set of known field names to guide correction. This fires only when the parser was built with ignoreUnknownFields=false.","triggerScenarios":"Submitting a request/object containing an undeclared field to an ObjectParser (or ConstructingObjectParser) created with ignoreUnknownFields=false. Typo in a field name, extra/unknown fields in a strict schema, or version skew where a field was removed/renamed.","commonSituations":"Strict REST endpoints that reject unknown fields. Aggregation/query parsing where an unsupported option is passed. Clients sending new fields to an older cluster, or vice versa.","solutions":["Remove or rename the offending field; consult the known-fields list in the message.","If extra fields should be tolerated, construct the parser with ignoreUnknownFields=true (where semantically safe).","Update the parser declaration to declare the new field if it's a legitimate addition."],"exampleFix":"// before: input has 'colour' but parser only knows 'color', ignoreUnknown=false\n{\"colour\": \"red\"}\n\n// after\n{\"color\": \"red\"}","handlingStrategy":"validation","validationCode":"// validate request keys against the parser's declared field set before parsing\nSet<String> allowed = ...; // declared field names for the active RestApiVersion\nSet<String> unknown = Sets.difference(body.keySet(), allowed);\nif (!unknown.isEmpty()) { /* reject with allowed list */ }","typeGuard":null,"tryCatchPattern":"try {\n    op.parse(parser, value, ctx);\n} catch (XContentParseException e) {\n    if (e.getMessage().contains(\"unknown field [\")) {\n        // extract field + known list, return 400 with allowed fields\n    }\n}","preventionTips":["Use ignoreUnknownFields=true where forward-compatible parsing is desired.","Publish and enforce an allowed-field schema at the REST boundary.","Keep parser field declarations in sync with API docs so unknowns are intentional."],"tags":["xcontent","object-parser","unknown-field","strict"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}