elastic/elasticsearch · error · IllegalArgumentException

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

Error message

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

What it means

Thrown by the lang-expression script engine when an expression calls a member method on a numeric field that is not one of the nine supported methods. Numeric fields expose: getValue(), isEmpty(), size(), min(), max(), avg(), median(), sum(), and count(). Any other method invocation on doc['<numeric_field>'].<method>() hits this default branch.

Source

Thrown at modules/lang-expression/src/main/java/org/elasticsearch/script/expression/NumericField.java:61

            case LENGTH_VARIABLE -> new CountMethodValueSource(fieldData);
            default -> throw new IllegalArgumentException(
                "Member variable [" + variable + "] does not exist for " + "numeric 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);
            default -> throw new IllegalArgumentException(
                "Member method [" + method + "] does not exist for numeric field [" + fieldName + "]."
            );
        };
    }
}

View on GitHub (pinned to db6a809a66)

Solutions

  1. Use only the supported method names: getValue(), isEmpty(), size(), min(), max(), avg(), median(), sum(), count()
  2. Check spelling: it's 'avg' not 'average', 'min' not 'getMin', 'median' not 'med'
  3. For unsupported statistics (stddev, percentiles), use painless or a metrics aggregation instead
  4. Verify the field is numeric with GET <index>/_mapping

Example fix

// before — expression script source:
doc['price'].getMin()

// after — use the correct terse method name:
doc['price'].min()
Defensive patterns

Strategy: validation

Validate before calling

// Validate numeric field methods before submission
Set<String> NUMERIC_METHODS = Set.of(
    "getValue", "isEmpty", "size", "min", "max", "avg", "median", "sum", "count"
);
// extract method name from doc['field'].<method>() and verify membership

Prevention

When it happens

Trigger: Writing an expression script that calls an unsupported method on a numeric field. Example: doc['price'].getMin() (note: it's 'min', not 'getMin'), doc['price'].average() (it's 'avg'), or doc['price'].stddev(). The method name is parsed by VariableContext as a METHOD-type context and routed to NumericField.getMethod when IndexNumericFieldData is detected.

Common situations: Using verbose Java-style names (getMin, getMaximum) instead of the terse forms (min, max). Expecting statistical methods not supported by the expression engine (stddev, variance, percentile). Confusing numeric field methods with date field methods (getYear, getHour). Copying method names from painless that have no expression equivalent.

Related errors


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