elastic/elasticsearch · error · IllegalArgumentException

field [{}] of type [{}] cannot be cast to [{}]

Error message

field [{}] of type [{}] cannot be cast to [{}]

What it means

IllegalArgumentException from AbstractStringProcessor when the source field is a scalar (non-list) value that is not a String — e.g. a number, boolean, or object. The processor requires a string input and will not implicitly coerce.

Source

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

                    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(
                    "field [" + field + "] of type [" + val.getClass().getName() + "] cannot be cast to [" + String.class.getName() + "]"
                );
            }

        }

        document.setFieldValue(targetField, newValue);
        return document;
    }

    protected abstract T process(String value);

    abstract static class Factory implements Processor.Factory {
        final String processorType;

        protected Factory(String processorType) {
            this.processorType = processorType;
        }

View on GitHub (pinned to db6a809a66)

Solutions

  1. Insert a convert processor (type: string) before this processor
  2. Target a field that is actually a string
  3. Use a script processor for custom coercion logic

Example fix

// before
{"processors":[{"uppercase":{"field":"port"}}]} // port=9200
// after
{"processors":[{"convert":{"field":"port","type":"string"}},{"uppercase":{"field":"port"}}]}
Defensive patterns

Strategy: type-guard

Type guard

// Only route scalar string fields to string processors:
boolean isStringScalar(Object v) { return v instanceof String; }

Try / catch

try { processor.execute(doc); }
catch (IllegalArgumentException e) {
    if (e.getMessage().contains("cannot be cast to")) { convert(doc, field, String.class); processor.execute(doc); }
    else throw e;
}

Prevention

When it happens

Trigger: The configured field holds a single non-string scalar; the final else branch in execute throws. Example: field 'port' = 9200 fed to an uppercase processor.

Common situations: Numeric/boolean fields mistakenly targeted by a string processor; schema drift changing a field's type; mappings inferred the field as long/boolean.

Related errors


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