elastic/elasticsearch · error · XContentParseException
[{}] {} doesn't support values of type: {}
Error message
[{}] {} doesn't support values of type: {} What it means
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.
Source
Thrown at libs/x-content/src/main/java/org/elasticsearch/xcontent/ObjectParser.java:706
this.parseField = parseField;
this.type = type;
}
void assertSupports(String parserName, XContentParser xContentParser, XContentParser.Token currentToken, String currentFieldName) {
boolean match = parseField.match(
parserName,
xContentParser::getTokenLocation,
currentFieldName,
xContentParser.getDeprecationHandler()
);
if (match == false) {
throw new XContentParseException(
xContentParser.getTokenLocation(),
"[" + parserName + "] parsefield doesn't accept: " + currentFieldName
);
}
if (supportedTokens.contains(xContentParser.currentToken()) == false) {
throw new XContentParseException(
xContentParser.getTokenLocation(),
"[" + parserName + "] " + currentFieldName + " doesn't support values of type: " + currentToken
);
}
}
@Override
public String toString() {
String[] deprecatedNames = parseField.getDeprecatedNames();
String allReplacedWith = parseField.getAllReplacedWith();
String deprecated = "";
if (deprecatedNames != null && deprecatedNames.length > 0) {
deprecated = ", deprecated_names=" + Arrays.toString(deprecatedNames);
}
return "FieldParser{"
+ "preferred_name="
+ parseField.getPreferredName()
+ ", supportedTokens="View on GitHub (pinned to db6a809a66)
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.
Example fix
// before — object where scalar number expected
{
"settings": { "number_of_shards": { "value": 3 } }
}
// after — plain number
{
"settings": { "number_of_shards": 3 }
} Defensive patterns
Strategy: validation
Validate before calling
// Before sending, validate each field value matches its expected JSON type
Map<String, JsonType> expectedTypes = Map.of("size", JsonType.NUMBER, "query", JsonType.OBJECT);
JsonNode node = mapper.readTree(json);
for (Map.Entry<String, JsonType> entry : expectedTypes.entrySet()) {
JsonNode val = node.get(entry.getKey());
if (val != null && !entry.getValue().matches(val)) {
throw new IllegalArgumentException(entry.getKey() + " must be " + entry.getValue());
}
} Try / catch
try {
objectParser.parse(parser, context);
} catch (XContentParseException e) {
if (e.getMessage().contains("doesn't support values of type")) {
return badRequest(e.getMessage());
}
throw e;
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- [{}] Expected START_OBJECT but was: {}
- Required one of fields {}, but none were specified.
- The following fields are not allowed together: {}
- [{}] failed to parse object
- [{}] doesn't support arrays. Use a single object with multip
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/7c27ac53046ed02b.
Report an issue: GitHub.