{"record":{"id":"12961e9d1d0d3c0c","repo":"elastic/elasticsearch","slug":"value-of-type-in-list-field-cannot","errorCode":null,"errorMessage":"value [{}] of type [{}] in list field [{}] cannot be cast to [{}]","messagePattern":"value \\[(.+?)\\] of type \\[(.+?)\\] in list field \\[(.+?)\\] cannot be cast to \\[(.+?)\\]","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/AbstractStringProcessor.java","lineNumber":69,"sourceCode":"\n    @Override\n    public final IngestDocument execute(IngestDocument document) {\n        Object val = document.getFieldValue(field, Object.class, ignoreMissing);\n        Object newValue;\n\n        if (val == null && ignoreMissing) {\n            return document;\n        } else if (val == null) {\n            throw new IllegalArgumentException(\"field [\" + field + \"] is null, cannot process it.\");\n        }\n\n        if (val instanceof List<?> list) {\n            List<Object> newList = new ArrayList<>(list.size());\n            for (Object value : list) {\n                if (value instanceof String string) {\n                    newList.add(process(string));\n                } else {\n                    throw new IllegalArgumentException(\n                        \"value [\"\n                            + value\n                            + \"] of type [\"\n                            + value.getClass().getName()\n                            + \"] in list field [\"\n                            + field\n                            + \"] cannot be cast to [\"\n                            + String.class.getName()\n                            + \"]\"\n                    );\n                }\n            }\n            newValue = newList;\n        } else {\n            if (val instanceof String string) {\n                newValue = process(string);\n            } else {\n                throw new IllegalArgumentException(","sourceCodeStart":51,"sourceCodeEnd":87,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/AbstractStringProcessor.java#L51-L87","documentation":"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.","triggerScenarios":"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.","commonSituations":"Mixed-type arrays in source documents; numeric IDs mixed with labels; dynamic mappings that allowed heterogeneous list values.","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"],"exampleFix":"// before\n{\"processors\":[{\"uppercase\":{\"field\":\"tags\"}}]} // tags=[\"web\",42]\n// after: coerce first\n{\"processors\":[{\"convert\":{\"field\":\"tags\",\"type\":\"string\",\"ignore_missing\":true}},{\"uppercase\":{\"field\":\"tags\"}}]}","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// Reject non-string list elements before the string processor:\nboolean allStrings(Object v) {\n    return !(v instanceof List<?> l) || l.stream().allMatch(e -> e == null || e instanceof String);\n}","tryCatchPattern":"try { processor.execute(doc); }\ncatch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"in list field\") && e.getMessage().contains(\"cannot be cast\")) {\n        convertToStringList(doc, field); processor.execute(doc);\n    } else throw e;\n}","preventionTips":["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"],"tags":["ingest","string-processor","type-cast","list"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}