elastic/elasticsearch · error · ParseException
Field [{}] does not exist in mappings
Error message
Field [{}] does not exist in mappings What it means
Thrown in getDocValueSource() when the field name extracted from doc['fieldname'] resolves to a null MappedFieldType via lookup.fieldType(fieldname). This means no field with that name exists in the current index mapping.
Source
Thrown at modules/lang-expression/src/main/java/org/elasticsearch/script/expression/ExpressionScriptEngine.java:446
methodname = parts[3].text;
dateAccessor = true;
} else if (parts[3].type == VariableContext.Type.MEMBER) {
variablename = parts[3].text;
dateAccessor = true;
}
}
if (dateAccessor == false) {
throw new IllegalArgumentException(
"Variable [" + variable + "] does not follow an allowed format of either doc['field'] or doc['field'].method()"
);
}
}
String fieldname = parts[1].text;
MappedFieldType fieldType = lookup.fieldType(fieldname);
if (fieldType == null) {
throw new ParseException("Field [" + fieldname + "] does not exist in mappings", 5);
}
IndexFieldData<?> fieldData = lookup.getForField(fieldType, MappedFieldType.FielddataOperation.SEARCH);
final DoubleValuesSource valueSource;
if (fieldType instanceof GeoPointFieldType) {
// geo
if (methodname == null) {
valueSource = GeoField.getVariable(fieldData, fieldname, variablename);
} else {
valueSource = GeoField.getMethod(fieldData, fieldname, methodname);
}
} else if (fieldType instanceof DateFieldMapper.DateFieldType) {
if (dateAccessor) {
// date object
if (methodname == null) {
valueSource = DateObject.getVariable(fieldData, fieldname, variablename);
} else {
valueSource = DateObject.getMethod(fieldData, fieldname, methodname);View on GitHub (pinned to db6a809a66)
Solutions
- Verify the field exists in the index mapping: GET <index>/_mapping — look for the field name.
- Check for typos or case sensitivity issues in the field name.
- If querying an alias or data stream, ensure all backing indices have the field.
- Add the field to the mapping if it should exist, or update the expression to reference the correct field name.
Example fix
// before: field name typo "source": "doc['prize'].value" // after: correct field name after checking mapping GET my-index/_mapping "source": "doc['price'].value"
Defensive patterns
Strategy: validation
Validate before calling
// Verify the field exists in the mapping before using it in an expression GET my-index/_mapping // Programmatically, check the mapping response for each field referenced as doc['fieldname'] // If the field is not in the mapping, do not use it in an expression
Try / catch
try {
engine.compile(scriptName, scriptSource, context, params);
} catch (ScriptException e) {
if (e.getCause() instanceof ParseException
&& e.getCause().getMessage().contains("does not exist in mappings")) {
String fieldName = extractFieldName(e.getCause().getMessage());
logger.error("Field '{}' does not exist — check mapping or fix the expression", fieldName);
}
throw e;
} Prevention
- Always verify field names against the index mapping before deploying expressions.
- When querying aliases or data streams, ensure all backing indices have the referenced fields.
- Update expressions when mappings change — field renames or removals will break existing scripts.
- Use a mapping validation step in your deployment pipeline for expression scripts.
When it happens
Trigger: Expression references doc['nonexistent'] where 'nonexistent' is not defined in the index mapping. The field name is extracted from the bracket notation, looked up in the index mapping, and null is returned.
Common situations: Typo in field name; field was removed or renamed in a mapping change; querying a different index than expected; field exists only in some indices of an alias/data stream but not all.
Related errors
- link error
- Unknown variable [{}]
- Field [{}] must be numeric, date, or geopoint
- Can't advance to doc using {}
- Error evaluating {}
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/f10ba3f5a6804866.
Report an issue: GitHub.