elastic/elasticsearch · error · IllegalArgumentException
Member variable [{}] does not exist for date field [{}].
Error message
Member variable [{}] does not exist for date field [{}]. What it means
Thrown by DateField.getVariable (lang-expression script engine) when an expression references an unsupported member VARIABLE on a date field. For date fields the only valid variables are 'value', 'empty', and 'length'. Any other variable name in doc['<dateField>'].<var> reaches the default branch.
Source
Thrown at modules/lang-expression/src/main/java/org/elasticsearch/script/expression/DateField.java:53
static final String AVERAGE_METHOD = "avg";
static final String MEDIAN_METHOD = "median";
static final String SUM_METHOD = "sum";
static final String COUNT_METHOD = "count";
// date-specific
static final String GET_YEAR_METHOD = "getYear";
static final String GET_MONTH_METHOD = "getMonth";
static final String GET_DAY_OF_MONTH_METHOD = "getDayOfMonth";
static final String GET_HOUR_OF_DAY_METHOD = "getHourOfDay";
static final String GET_MINUTES_METHOD = "getMinutes";
static final String GET_SECONDS_METHOD = "getSeconds";
static DoubleValuesSource getVariable(IndexFieldData<?> fieldData, String fieldName, String variable) {
return switch (variable) {
case VALUE_VARIABLE -> new FieldDataValueSource(fieldData, MultiValueMode.MIN);
case EMPTY_VARIABLE -> new EmptyMemberValueSource(fieldData);
case LENGTH_VARIABLE -> new CountMethodValueSource(fieldData);
default -> throw new IllegalArgumentException(
"Member variable [" + variable + "] does not exist for date field [" + fieldName + "]."
);
};
}
static DoubleValuesSource getMethod(IndexFieldData<?> fieldData, String fieldName, String method) {
return switch (method) {
case GETVALUE_METHOD -> new FieldDataValueSource(fieldData, MultiValueMode.MIN);
case ISEMPTY_METHOD -> new EmptyMemberValueSource(fieldData);
case SIZE_METHOD -> new CountMethodValueSource(fieldData);
case MINIMUM_METHOD -> new FieldDataValueSource(fieldData, MultiValueMode.MIN);
case MAXIMUM_METHOD -> new FieldDataValueSource(fieldData, MultiValueMode.MAX);
case AVERAGE_METHOD -> new FieldDataValueSource(fieldData, MultiValueMode.AVG);
case MEDIAN_METHOD -> new FieldDataValueSource(fieldData, MultiValueMode.MEDIAN);
case SUM_METHOD -> new FieldDataValueSource(fieldData, MultiValueMode.SUM);
case COUNT_METHOD -> new CountMethodValueSource(fieldData);
case GET_YEAR_METHOD -> new DateMethodValueSource(fieldData, MultiValueMode.MIN, method, Calendar.YEAR);
case GET_MONTH_METHOD -> new DateMethodValueSource(fieldData, MultiValueMode.MIN, method, Calendar.MONTH);View on GitHub (pinned to db6a809a66)
Solutions
- Use a supported variable: doc['timestamp'].value, doc['timestamp'].empty, or doc['timestamp'].length.
- For date components, use the date object: doc['timestamp'].date.year (variable) or doc['timestamp'].date.getYear (method).
- Switch to a supported method on the field: doc['timestamp'].getYear, .getMonth, etc.
Example fix
// before (expression script) doc['timestamp'].year // after doc['timestamp'].date.year // or doc['timestamp'].getYear
Defensive patterns
Strategy: validation
Validate before calling
// Validate expression variable before using it on a date field
Set<String> OK = Set.of("value", "empty", "length");
if (!OK.contains(variable)) {
throw new IllegalArgumentException("Unsupported date field variable: " + variable + "; use .date.<var> for components");
} Prevention
- For date fields, only value/empty/length are valid variables.
- Use doc['field'].date.<component> for date parts, not doc['field'].<component>.
- Keep a cheat-sheet of expression field vs date-object vocabularies.
When it happens
Trigger: Using an expression script (lang: expression) like doc['timestamp'].year or doc['timestamp'].foo where 'timestamp' is a date field. Date FIELD variables are limited to value/empty/length; rich date accessors live on the date OBJECT (doc['timestamp'].date.<var>, see DateObject).
Common situations: Confusing date-field variables with date-object variables; copying a painless-style accessor into an expression script; assuming getYear-style accessors work as variables rather than methods.
Related errors
- Member method [{}] does not exist for date field [{}].
- Member variable [{}] does not exist for date object on field
- Member method [{}] does not exist for date object on field [
- Error evaluating {}
- Can't advance to doc using {}
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/5853f3717857b226.
Report an issue: GitHub.