{"record":{"id":"7c27ac53046ed02b","repo":"elastic/elasticsearch","slug":"doesn-t-support-values-of-type","errorCode":null,"errorMessage":"[{}] {} doesn't support values of type: {}","messagePattern":"\\[(.+?)\\] (.+?) doesn't support values of type: (.+?)","errorType":"exception","errorClass":"XContentParseException","httpStatus":null,"severity":"error","filePath":"libs/x-content/src/main/java/org/elasticsearch/xcontent/ObjectParser.java","lineNumber":706,"sourceCode":"            this.parseField = parseField;\n            this.type = type;\n        }\n\n        void assertSupports(String parserName, XContentParser xContentParser, XContentParser.Token currentToken, String currentFieldName) {\n            boolean match = parseField.match(\n                parserName,\n                xContentParser::getTokenLocation,\n                currentFieldName,\n                xContentParser.getDeprecationHandler()\n            );\n            if (match == false) {\n                throw new XContentParseException(\n                    xContentParser.getTokenLocation(),\n                    \"[\" + parserName + \"] parsefield doesn't accept: \" + currentFieldName\n                );\n            }\n            if (supportedTokens.contains(xContentParser.currentToken()) == false) {\n                throw new XContentParseException(\n                    xContentParser.getTokenLocation(),\n                    \"[\" + parserName + \"] \" + currentFieldName + \" doesn't support values of type: \" + currentToken\n                );\n            }\n        }\n\n        @Override\n        public String toString() {\n            String[] deprecatedNames = parseField.getDeprecatedNames();\n            String allReplacedWith = parseField.getAllReplacedWith();\n            String deprecated = \"\";\n            if (deprecatedNames != null && deprecatedNames.length > 0) {\n                deprecated = \", deprecated_names=\" + Arrays.toString(deprecatedNames);\n            }\n            return \"FieldParser{\"\n                + \"preferred_name=\"\n                + parseField.getPreferredName()\n                + \", supportedTokens=\"","sourceCodeStart":688,"sourceCodeEnd":724,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/libs/x-content/src/main/java/org/elasticsearch/xcontent/ObjectParser.java#L688-L724","documentation":"Thrown inside FieldParser.assertSupports when the current XContentParser token is not in the FieldParser's supportedTokens EnumSet. Each declared field registers the set of token types it can handle (e.g., VALUE_NUMBER, VALUE_STRING, START_OBJECT). If the actual token does not match, the field value's type is incompatible with the field declaration.","triggerScenarios":"Providing a JSON object where a scalar is expected (e.g., {\"size\": {\"value\": 10}} when the field expects a number). Providing an array where a single value is expected. Providing a string where a boolean or object is expected. The token type is structurally incompatible with what the field parser can consume.","commonSituations":"Mapping a field as integer but sending an object. Sending a string where a boolean is expected without coercion. Nesting an extra level of braces. Client serialization producing a different JSON structure than the server expects.","solutions":["Change the field value to the correct JSON type indicated by the error message (it says which type was found).","Check the mapping or API spec for the expected value type of the field.","If the value legitimately needs a different representation, check whether the field supports that token type.","Validate the JSON structure field-by-field against the endpoint schema before sending."],"exampleFix":"// before — object where scalar number expected\n{\n  \"settings\": { \"number_of_shards\": { \"value\": 3 } }\n}\n\n// after — plain number\n{\n  \"settings\": { \"number_of_shards\": 3 }\n}","handlingStrategy":"validation","validationCode":"// Before sending, validate each field value matches its expected JSON type\nMap<String, JsonType> expectedTypes = Map.of(\"size\", JsonType.NUMBER, \"query\", JsonType.OBJECT);\nJsonNode node = mapper.readTree(json);\nfor (Map.Entry<String, JsonType> entry : expectedTypes.entrySet()) {\n    JsonNode val = node.get(entry.getKey());\n    if (val != null && !entry.getValue().matches(val)) {\n        throw new IllegalArgumentException(entry.getKey() + \" must be \" + entry.getValue());\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    objectParser.parse(parser, context);\n} catch (XContentParseException e) {\n    if (e.getMessage().contains(\"doesn't support values of type\")) {\n        return badRequest(e.getMessage());\n    }\n    throw e;\n}","preventionTips":["Use JSON schema validation on the request body to enforce correct value types per field.","Match client serialization to the expected JSON token types for each field.","Test with intentionally wrong types to verify the error message is clear and actionable."],"tags":["parsing","xcontent","type-mismatch","token-type","object-parser"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}