{"record":{"id":"80f20c1e43fee231","repo":"elastic/elasticsearch","slug":"member-variable-does-not-exist-for-numeric-fi","errorCode":null,"errorMessage":"Member variable [{}] does not exist for numeric field [{}].","messagePattern":"Member variable \\[(.+?)\\] does not exist for numeric field \\[(.+?)\\]\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/lang-expression/src/main/java/org/elasticsearch/script/expression/NumericField.java","lineNumber":44,"sourceCode":"    static final String LENGTH_VARIABLE = \"length\";\n\n    // supported methods\n    static final String GETVALUE_METHOD = \"getValue\";\n    static final String ISEMPTY_METHOD = \"isEmpty\";\n    static final String SIZE_METHOD = \"size\";\n    static final String MINIMUM_METHOD = \"min\";\n    static final String MAXIMUM_METHOD = \"max\";\n    static final String AVERAGE_METHOD = \"avg\";\n    static final String MEDIAN_METHOD = \"median\";\n    static final String SUM_METHOD = \"sum\";\n    static final String COUNT_METHOD = \"count\";\n\n    static DoubleValuesSource getVariable(IndexFieldData<?> fieldData, String fieldName, String variable) {\n        return switch (variable) {\n            case VALUE_VARIABLE -> new FieldDataValueSource(fieldData, MultiValueMode.MIN);\n            case EMPTY_VARIABLE -> new EmptyMemberValueSource(fieldData);\n            case LENGTH_VARIABLE -> new CountMethodValueSource(fieldData);\n            default -> throw new IllegalArgumentException(\n                \"Member variable [\" + variable + \"] does not exist for \" + \"numeric field [\" + fieldName + \"].\"\n            );\n        };\n    }\n\n    static DoubleValuesSource getMethod(IndexFieldData<?> fieldData, String fieldName, String method) {\n        return switch (method) {\n            case GETVALUE_METHOD -> new FieldDataValueSource(fieldData, MultiValueMode.MIN);\n            case ISEMPTY_METHOD -> new EmptyMemberValueSource(fieldData);\n            case SIZE_METHOD -> new CountMethodValueSource(fieldData);\n            case MINIMUM_METHOD -> new FieldDataValueSource(fieldData, MultiValueMode.MIN);\n            case MAXIMUM_METHOD -> new FieldDataValueSource(fieldData, MultiValueMode.MAX);\n            case AVERAGE_METHOD -> new FieldDataValueSource(fieldData, MultiValueMode.AVG);\n            case MEDIAN_METHOD -> new FieldDataValueSource(fieldData, MultiValueMode.MEDIAN);\n            case SUM_METHOD -> new FieldDataValueSource(fieldData, MultiValueMode.SUM);\n            case COUNT_METHOD -> new CountMethodValueSource(fieldData);\n            default -> throw new IllegalArgumentException(\n                \"Member method [\" + method + \"] does not exist for numeric field [\" + fieldName + \"].\"","sourceCodeStart":26,"sourceCodeEnd":62,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/NumericField.java#L26-L62","documentation":"Thrown by the lang-expression script engine when an expression references a member variable on a numeric field that is not one of the three supported names. Numeric fields expose exactly three member variables: 'value', 'empty', and 'length'. Any other member access on doc['<numeric_field>'].<variable> hits this default branch.","triggerScenarios":"Writing an expression script that accesses a numeric field with an unsupported member variable. Example: doc['price'].min or doc['price'].avg — these are methods, not variables. The variable name is parsed by VariableContext and routed to NumericField.getVariable only when the field data is IndexNumericFieldData.","commonSituations":"Confusing member variables (dot syntax, no parentheses) with member methods (parentheses). For example, doc['price'].min is a variable access that fails; doc['price'].min() is a method call that works. Expecting aggregation-like sub-fields (sum, avg, median) to be available as bare variables rather than methods. Misspelling 'value' as 'val'.","solutions":["Use only 'value', 'empty', or 'length' as member variables on numeric fields: doc['price'].value (or just doc['price'] which defaults to .value)","For statistics like min, max, avg, sum, use the method form: doc['price'].min(), doc['price'].max(), doc['price'].avg(), doc['price'].sum()","Drop the member entirely for the default value: doc['price'] is equivalent to doc['price'].value","Confirm the field is numeric via GET <index>/_mapping — non-numeric fields route to a different handler"],"exampleFix":"// before — expression script source:\ndoc['price'].min\n\n// after — 'min' is a method, not a variable:\ndoc['price'].min()","handlingStrategy":"validation","validationCode":"// Validate numeric field member variables before submission\nSet<String> NUMERIC_VARS = Set.of(\"value\", \"empty\", \"length\");\n// extract member after doc['field']. and verify it's in NUMERIC_VARS\n// Note: doc['field'] without a member defaults to .value","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Remember: statistics like min, max, avg are METHODS not variables — they need parentheses","Bare doc['field'] is equivalent to doc['field'].value","Only value, empty, and length are valid as dot-syntax variables on numeric fields"],"tags":["elasticsearch","lang-expression","numeric","script","expression"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T06:17:24.410Z"}