{"record":{"id":"97bcf07b17face29","repo":"elastic/elasticsearch","slug":"field-should-contain-only-string-or-array-of","errorCode":null,"errorMessage":"field [{}] should contain only string or array of strings","messagePattern":"field \\[(.+?)\\] should contain only string or array of strings","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/ingest-ip-location/src/main/java/org/elasticsearch/ingest/iplocation/GeoIpProcessor.java","lineNumber":144,"sourceCode":"                    }\n                    return document;\n                }\n                if (data.isEmpty()) {\n                    dataList.add(null);\n                    continue;\n                }\n                if (firstOnly) {\n                    writeGeoIpData(document, targetField, data);\n                    return document;\n                }\n                match = true;\n                dataList.add(data);\n            }\n            if (match) {\n                writeGeoIpDataList(document, targetField, dataList);\n            }\n        } else {\n            throw new IllegalArgumentException(\"field [\" + field + \"] should contain only string or array of strings\");\n        }\n\n        return document;\n    }\n\n    @Override\n    public String getType() {\n        return type;\n    }\n\n    String getField() {\n        return field;\n    }\n\n    String getTargetField() {\n        return targetField;\n    }\n","sourceCodeStart":126,"sourceCodeEnd":162,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/ingest-ip-location/src/main/java/org/elasticsearch/ingest/iplocation/GeoIpProcessor.java#L126-L162","documentation":"Thrown by GeoIpProcessor.execute when the source field value is neither a String nor a List. The processor only accepts a single string IP or an array of string IPs; any other type (number, object, boolean) hits the final else branch.","triggerScenarios":"The configured field holds a scalar non-string value (e.g., a numeric IP representation, a boolean, a nested object, or a Long).","commonSituations":"Field type changes upstream (e.g., IP stored as a long integer). Nested objects where the field points to a map. Misconfigured field path resolving to the wrong nested structure.","solutions":["Use a convert processor upstream to cast the field to string.","Correct the field path to point at the actual IP string value.","Add a script processor to normalize the value to a string before geoip."],"exampleFix":"// before: client_ip is a numeric value\n{\n  \"geoip\": { \"field\": \"client_ip\", \"target_field\": \"geo\" }\n}\n// after: convert to string first\n{\n  \"convert\": { \"field\": \"client_ip\", \"type\": \"string\" } },\n{\n  \"geoip\": { \"field\": \"client_ip\", \"target_field\": \"geo\" }\n}","handlingStrategy":"type-guard","validationCode":"// Verify the field is String or List before geoip\nObject v = document.getFieldValue(\"client_ip\", Object.class, true);\nif (v != null && !(v instanceof String) && !(v instanceof List)) {\n    // add a convert processor or fix the field path\n}","typeGuard":"boolean isStringOrStringArray(IngestDocument doc, String field) {\n    Object v = doc.getFieldValue(field, Object.class, true);\n    return v instanceof String || v instanceof List;\n}","tryCatchPattern":"try {\n    // run geoip processor\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"should contain only string or array of strings\")) {\n        // add a convert processor to cast to string\n    } else { throw e; }\n}","preventionTips":["Use a convert processor to cast the IP field to string before geoip.","Verify the field path resolves to the actual IP value, not a nested object.","Add a script processor to normalize non-string IP representations."],"tags":["elasticsearch","ingest-pipeline","geoip","type-mismatch","validation"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:17:08.281Z"}