{"record":{"id":"2e2986abb8bc0931","repo":"elastic/elasticsearch","slug":"member-variable-does-not-exist-for-geo-field","errorCode":null,"errorMessage":"Member variable [{}] does not exist for geo field [{}].","messagePattern":"Member variable \\[(.+?)\\] does not exist for geo field \\[(.+?)\\]\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/lang-expression/src/main/java/org/elasticsearch/script/expression/GeoField.java","lineNumber":37,"sourceCode":"    // no instance\n    private GeoField() {}\n\n    // supported variables\n    static final String EMPTY_VARIABLE = \"empty\";\n    static final String LAT_VARIABLE = \"lat\";\n    static final String LON_VARIABLE = \"lon\";\n\n    // supported methods\n    static final String ISEMPTY_METHOD = \"isEmpty\";\n    static final String GETLAT_METHOD = \"getLat\";\n    static final String GETLON_METHOD = \"getLon\";\n\n    static DoubleValuesSource getVariable(IndexFieldData<?> fieldData, String fieldName, String variable) {\n        return switch (variable) {\n            case EMPTY_VARIABLE -> new GeoEmptyValueSource(fieldData);\n            case LAT_VARIABLE -> new GeoLatitudeValueSource(fieldData);\n            case LON_VARIABLE -> new GeoLongitudeValueSource(fieldData);\n            default -> throw new IllegalArgumentException(\n                \"Member variable [\" + variable + \"] does not exist for geo field [\" + fieldName + \"].\"\n            );\n        };\n    }\n\n    static DoubleValuesSource getMethod(IndexFieldData<?> fieldData, String fieldName, String method) {\n        return switch (method) {\n            case ISEMPTY_METHOD -> new GeoEmptyValueSource(fieldData);\n            case GETLAT_METHOD -> new GeoLatitudeValueSource(fieldData);\n            case GETLON_METHOD -> new GeoLongitudeValueSource(fieldData);\n            default -> throw new IllegalArgumentException(\n                \"Member method [\" + method + \"] does not exist for geo field [\" + fieldName + \"].\"\n            );\n        };\n    }\n}\n","sourceCodeStart":19,"sourceCodeEnd":54,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/GeoField.java#L19-L54","documentation":"Thrown by the lang-expression script engine when an expression references a member variable on a geo_point field that is not one of the three supported names. Geo fields expose exactly three member variables: 'empty', 'lat', and 'lon'. Any other member access on doc['<geo_field>'].<variable> hits this default branch in the switch statement.","triggerScenarios":"Writing an expression script (\"source\": \"expression\", e.g. in a script_score, sort, or aggregation) that accesses a geo_point field with an unsupported member variable. Example: doc['location'].altitude or doc['location'].geohash where 'location' is mapped as geo_point. The variable name is parsed by VariableContext and routed to GeoField.getVariable only when the field type is GeoPointFieldType.","commonSituations":"Assuming geo_point fields expose arbitrary sub-fields like geohash, altitude, or distance. Copying an expression from a numeric or date field example without adjusting for the geo API. Misspelling 'lat' or 'lon' (e.g., 'latitude'). Confusing member variables (dot syntax) with member methods (parenthesis syntax).","solutions":["Use only 'lat', 'lon', or 'empty' as member variables on geo_point fields: doc['location'].lat, doc['location'].lon, doc['location'].empty","If you need a method-style access, use the method forms: doc['location'].getLat(), doc['location'].getLon(), doc['location'].isEmpty()","If you need geo distance or geohash computation, use a painless script or a dedicated geo query/aggregation instead of the expression language","Check the field mapping with GET <index>/_mapping to confirm the field is actually geo_point"],"exampleFix":"// before — expression script source:\ndoc['location'].altitude\n\n// after — use the supported member variable:\ndoc['location'].lat","handlingStrategy":"validation","validationCode":"// Validate expression script geo field member variables before submission\nSet<String> GEO_VARS = Set.of(\"empty\", \"lat\", \"lon\");\nString extractMember(String exprRef) {\n    // extract the member after doc['field'].\n    int dot = exprRef.lastIndexOf('.');\n    return dot >= 0 ? exprRef.substring(dot + 1) : \"value\";\n}\n// before sending: assert GEO_VARS.contains(extractMember(variableRef))","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep a reference card of geo_point member variables: empty, lat, lon","Use doc['field'].lat / .lon instead of guessing sub-field names","Validate expression scripts in a dev environment before deploying to production"],"tags":["elasticsearch","lang-expression","geo-point","script","expression"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}