{"record":{"id":"f10ba3f5a6804866","repo":"elastic/elasticsearch","slug":"field-does-not-exist-in-mappings","errorCode":null,"errorMessage":"Field [{}] does not exist in mappings","messagePattern":"Field \\[(.+?)\\] does not exist in mappings","errorType":"validation","errorClass":"ParseException","httpStatus":null,"severity":"error","filePath":"modules/lang-expression/src/main/java/org/elasticsearch/script/expression/ExpressionScriptEngine.java","lineNumber":446,"sourceCode":"                    methodname = parts[3].text;\n                    dateAccessor = true;\n                } else if (parts[3].type == VariableContext.Type.MEMBER) {\n                    variablename = parts[3].text;\n                    dateAccessor = true;\n                }\n            }\n            if (dateAccessor == false) {\n                throw new IllegalArgumentException(\n                    \"Variable [\" + variable + \"] does not follow an allowed format of either doc['field'] or doc['field'].method()\"\n                );\n            }\n        }\n\n        String fieldname = parts[1].text;\n        MappedFieldType fieldType = lookup.fieldType(fieldname);\n\n        if (fieldType == null) {\n            throw new ParseException(\"Field [\" + fieldname + \"] does not exist in mappings\", 5);\n        }\n\n        IndexFieldData<?> fieldData = lookup.getForField(fieldType, MappedFieldType.FielddataOperation.SEARCH);\n        final DoubleValuesSource valueSource;\n        if (fieldType instanceof GeoPointFieldType) {\n            // geo\n            if (methodname == null) {\n                valueSource = GeoField.getVariable(fieldData, fieldname, variablename);\n            } else {\n                valueSource = GeoField.getMethod(fieldData, fieldname, methodname);\n            }\n        } else if (fieldType instanceof DateFieldMapper.DateFieldType) {\n            if (dateAccessor) {\n                // date object\n                if (methodname == null) {\n                    valueSource = DateObject.getVariable(fieldData, fieldname, variablename);\n                } else {\n                    valueSource = DateObject.getMethod(fieldData, fieldname, methodname);","sourceCodeStart":428,"sourceCodeEnd":464,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/ExpressionScriptEngine.java#L428-L464","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before: field name typo\n\"source\": \"doc['prize'].value\"\n// after: correct field name after checking mapping\nGET my-index/_mapping\n\"source\": \"doc['price'].value\"","handlingStrategy":"validation","validationCode":"// Verify the field exists in the mapping before using it in an expression\nGET my-index/_mapping\n// Programmatically, check the mapping response for each field referenced as doc['fieldname']\n// If the field is not in the mapping, do not use it in an expression","typeGuard":null,"tryCatchPattern":"try {\n    engine.compile(scriptName, scriptSource, context, params);\n} catch (ScriptException e) {\n    if (e.getCause() instanceof ParseException\n        && e.getCause().getMessage().contains(\"does not exist in mappings\")) {\n        String fieldName = extractFieldName(e.getCause().getMessage());\n        logger.error(\"Field '{}' does not exist — check mapping or fix the expression\", fieldName);\n    }\n    throw e;\n}","preventionTips":["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."],"tags":["expression","script","field-mapping","binding","missing-field"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}