elastic/elasticsearch · error · IllegalArgumentException

Member method [{}] does not exist for date field [{}].

Error message

Member method [{}] does not exist for date field [{}].

What it means

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.

Source

Thrown at modules/lang-expression/src/main/java/org/elasticsearch/script/expression/DateField.java:76

    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);
            case GET_DAY_OF_MONTH_METHOD -> new DateMethodValueSource(fieldData, MultiValueMode.MIN, method, Calendar.DAY_OF_MONTH);
            case GET_HOUR_OF_DAY_METHOD -> new DateMethodValueSource(fieldData, MultiValueMode.MIN, method, Calendar.HOUR_OF_DAY);
            case GET_MINUTES_METHOD -> new DateMethodValueSource(fieldData, MultiValueMode.MIN, method, Calendar.MINUTE);
            case GET_SECONDS_METHOD -> new DateMethodValueSource(fieldData, MultiValueMode.MIN, method, Calendar.SECOND);
            default -> throw new IllegalArgumentException(
                "Member method [" + method + "] does not exist for date field [" + fieldName + "]."
            );
        };
    }
}

View on GitHub (pinned to db6a809a66)

Solutions

  1. 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.
  2. For other date components (era, dayOfWeek, etc.), switch to the date object: doc['timestamp'].date.getDayOfWeek().
  3. If no accessor exists, precompute the value at index time into a numeric field.

Example fix

// before
doc['timestamp'].getDay()

// after
doc['timestamp'].getDayOfMonth()
Defensive patterns

Strategy: validation

Validate before calling

Set<String> OK_METHODS = Set.of(
    "getValue","isEmpty","size","min","max","avg","median","sum","count",
    "getYear","getMonth","getDayOfMonth","getHourOfDay","getMinutes","getSeconds");
if (!OK_METHODS.contains(method)) {
    throw new IllegalArgumentException("Unsupported date field method: " + method);
}

Prevention

When it happens

Trigger: 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().

Common situations: 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.

Related errors


AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12). Data as JSON: /api/errors/7ce8fb9dff403fde. Report an issue: GitHub.