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
- Add a convert processor (to string) upstream for the offending list elements
- Normalize the source so list elements are homogeneous strings
- 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
- Insert a convert (type: string) processor before string processors on polymorphic lists
- Enforce homogeneous list typing in source mappings
- Add a script processor to coerce mixed-type arrays defensively
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
- field [{}] of type [{}] cannot be cast to [{}]
- field [{}] is null, cannot process it.
- Plugins directory missing: {pluginsDir}
- Unable to find pattern [{}] in Grok's pattern dictionary
- circular reference in pattern back [{}]
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/12961e9d1d0d3c0c.
Report an issue: GitHub.