{"record":{"id":"7ce8fb9dff403fde","repo":"elastic/elasticsearch","slug":"member-method-does-not-exist-for-date-field","errorCode":null,"errorMessage":"Member method [{}] does not exist for date field [{}].","messagePattern":"Member method \\[(.+?)\\] does not exist for date field \\[(.+?)\\]\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/lang-expression/src/main/java/org/elasticsearch/script/expression/DateField.java","lineNumber":76,"sourceCode":"\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            case GET_YEAR_METHOD -> new DateMethodValueSource(fieldData, MultiValueMode.MIN, method, Calendar.YEAR);\n            case GET_MONTH_METHOD -> new DateMethodValueSource(fieldData, MultiValueMode.MIN, method, Calendar.MONTH);\n            case GET_DAY_OF_MONTH_METHOD -> new DateMethodValueSource(fieldData, MultiValueMode.MIN, method, Calendar.DAY_OF_MONTH);\n            case GET_HOUR_OF_DAY_METHOD -> new DateMethodValueSource(fieldData, MultiValueMode.MIN, method, Calendar.HOUR_OF_DAY);\n            case GET_MINUTES_METHOD -> new DateMethodValueSource(fieldData, MultiValueMode.MIN, method, Calendar.MINUTE);\n            case GET_SECONDS_METHOD -> new DateMethodValueSource(fieldData, MultiValueMode.MIN, method, Calendar.SECOND);\n            default -> throw new IllegalArgumentException(\n                \"Member method [\" + method + \"] does not exist for date field [\" + fieldName + \"].\"\n            );\n        };\n    }\n}\n","sourceCodeStart":58,"sourceCodeEnd":82,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/lang-expression/src/main/java/org/elasticsearch/script/expression/DateField.java#L58-L82","documentation":"Thrown by DateField.getMethod when an expression script calls an unsupported member METHOD on a date field. Supported methods are getValue, isEmpty, size, min, max, avg, median, sum, count, plus the date accessors getYear, getMonth, getDayOfMonth, getHourOfDay, getMinutes, getSeconds. Any other method name hits the default branch.","triggerScenarios":"Writing doc['timestamp'].<method>() in a lang: expression script where <method> is not in the supported list, e.g. doc['timestamp'].getDay() (the correct name is getDayOfMonth) or doc['timestamp'].toString().","commonSituations":"Misspelling a method name; using Joda/java.time method names that don't match the expression engine's vocabulary; assuming a generic method like 'toString' exists.","solutions":["Use one of the supported method names exactly: getYear, getMonth, getDayOfMonth, getHourOfDay, getMinutes, getSeconds, or the generic min/max/avg/median/sum/count/getValue/isEmpty/size.","For other date components (era, dayOfWeek, etc.), switch to the date object: doc['timestamp'].date.getDayOfWeek().","If no accessor exists, precompute the value at index time into a numeric field."],"exampleFix":"// before\ndoc['timestamp'].getDay()\n\n// after\ndoc['timestamp'].getDayOfMonth()","handlingStrategy":"validation","validationCode":"Set<String> OK_METHODS = Set.of(\n    \"getValue\",\"isEmpty\",\"size\",\"min\",\"max\",\"avg\",\"median\",\"sum\",\"count\",\n    \"getYear\",\"getMonth\",\"getDayOfMonth\",\"getHourOfDay\",\"getMinutes\",\"getSeconds\");\nif (!OK_METHODS.contains(method)) {\n    throw new IllegalArgumentException(\"Unsupported date field method: \" + method);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Use the exact method names the expression engine knows (e.g. getDayOfMonth, not getDay).","For other date components, use the date object's get* methods.","Pre-validate dynamic expression strings against the supported method set."],"tags":["elasticsearch","lang-expression","expression-script","date-field","method","validation"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:17:08.281Z"}