elastic/elasticsearch · error · IllegalArgumentException

value [{}] of type [{}] in list field [{}] cannot be cast to

Error message

value [{}] of type [{}] in list field [{}] cannot be cast to [{}]

What it means

IllegalArgumentException from AbstractStringProcessor when the source field holds a List but one of its elements is not a String. The processor can only operate on string elements, so a non-string element (number, object, boolean) aborts the whole list rather than coercing.

Source

Thrown at modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/AbstractStringProcessor.java:69

    @Override
    public final IngestDocument execute(IngestDocument document) {
        Object val = document.getFieldValue(field, Object.class, ignoreMissing);
        Object newValue;

        if (val == null && ignoreMissing) {
            return document;
        } else if (val == null) {
            throw new IllegalArgumentException("field [" + field + "] is null, cannot process it.");
        }

        if (val instanceof List<?> list) {
            List<Object> newList = new ArrayList<>(list.size());
            for (Object value : list) {
                if (value instanceof String string) {
                    newList.add(process(string));
                } else {
                    throw new IllegalArgumentException(
                        "value ["
                            + value
                            + "] of type ["
                            + value.getClass().getName()
                            + "] in list field ["
                            + field
                            + "] cannot be cast to ["
                            + String.class.getName()
                            + "]"
                    );
                }
            }
            newValue = newList;
        } else {
            if (val instanceof String string) {
                newValue = process(string);
            } else {
                throw new IllegalArgumentException(

View on GitHub (pinned to db6a809a66)

Solutions

  1. Add a convert processor (to string) upstream for the offending list elements
  2. Normalize the source so list elements are homogeneous strings
  3. Split the field, convert, and recombine before this processor

Example fix

// before
{"processors":[{"uppercase":{"field":"tags"}}]} // tags=["web",42]
// after: coerce first
{"processors":[{"convert":{"field":"tags","type":"string","ignore_missing":true}},{"uppercase":{"field":"tags"}}]}
Defensive patterns

Strategy: type-guard

Type guard

// Reject non-string list elements before the string processor:
boolean allStrings(Object v) {
    return !(v instanceof List<?> l) || l.stream().allMatch(e -> e == null || e instanceof String);
}

Try / catch

try { processor.execute(doc); }
catch (IllegalArgumentException e) {
    if (e.getMessage().contains("in list field") && e.getMessage().contains("cannot be cast")) {
        convertToStringList(doc, field); processor.execute(doc);
    } else throw e;
}

Prevention

When it happens

Trigger: The configured field resolves to a List whose elements include a non-String type; e.g. field 'tags' = ["web", 42, "api"]. The inner for-loop hits the else branch and throws.

Common situations: Mixed-type arrays in source documents; numeric IDs mixed with labels; dynamic mappings that allowed heterogeneous list values.

Related errors


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