{"record":{"id":"2f0d1373b2c135a6","repo":"elastic/elasticsearch","slug":"unable-to-convert-to-integer","errorCode":null,"errorMessage":"unable to convert [{}] to integer","messagePattern":"unable to convert \\[(.+?)\\] to integer","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ConvertProcessor.java","lineNumber":43,"sourceCode":"\n/**\n * Processor that converts fields content to a different type. Supported types are: integer, float, boolean and string.\n * Throws exception if the field is not there or the conversion fails.\n */\npublic final class ConvertProcessor extends AbstractProcessor {\n\n    enum Type {\n        INTEGER {\n            @Override\n            public Object convert(Object value) {\n                try {\n                    String strValue = value.toString();\n                    if (strValue.startsWith(\"0x\") || strValue.startsWith(\"-0x\")) {\n                        return Integer.decode(strValue);\n                    }\n                    return Integer.parseInt(strValue);\n                } catch (NumberFormatException e) {\n                    throw new IllegalArgumentException(\"unable to convert [\" + value + \"] to integer\", e);\n                }\n\n            }\n        },\n        LONG {\n            @Override\n            public Object convert(Object value) {\n                try {\n                    String strValue = value.toString();\n                    if (strValue.startsWith(\"0x\") || strValue.startsWith(\"-0x\")) {\n                        return Long.decode(strValue);\n                    }\n                    return Long.parseLong(strValue);\n                } catch (NumberFormatException e) {\n                    throw new IllegalArgumentException(\"unable to convert [\" + value + \"] to long\", e);\n                }\n            }\n        },","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ConvertProcessor.java#L25-L61","documentation":"ConvertProcessor.Type.INTEGER.convert calls Integer.parseInt (or Integer.decode for '0x' / '-0x' prefixes) on value.toString(); a NumberFormatException is wrapped as IllegalArgumentException. The original value (via toString) is in the message. Thrown from ConvertProcessor.execute for both scalar and list values.","triggerScenarios":"convert processor with type: integer on a value that is not parseable: 'abc', '1.5' (Integer.parseInt rejects decimal), 'true', empty string '', '0xZZ'. Hex values must be valid Integer.decode input. Multi-valued fields fail on the first unparseable element.","commonSituations":"Source field contains decimal numbers ('1.0') the user expected to convert to integer; quoted numeric strings with currency symbols; locale-specific number formats; empty strings from sparse data.","solutions":["If the value is decimal, convert via a two-step: type: double then a script to cast, or pre-round.","Strip currency symbols, whitespace, and thousands separators before the convert processor.","Set ignore_missing: true if the field is sometimes absent, or filter empty strings upstream.","Use on_failure to quarantine unconvertible values."],"exampleFix":"// before — decimal string cannot be parsed as integer\n//   { \"convert\": { \"field\": \"count\", \"type\": \"integer\" } }  // count = \"1.5\"\n//\n// after — accept decimal, then truncate via script\n//   { \"convert\": { \"field\": \"count\", \"type\": \"double\" } },\n//   { \"script\": { \"source\": \"ctx.count = (int) ctx.count\" } }","handlingStrategy":"validation","validationCode":"boolean isParsableAsInteger(Object v) {\n    if (v == null) return false;\n    String s = v.toString();\n    try { Integer.decode(s); return true; } catch (NumberFormatException ignored) {}\n    try { Integer.parseInt(s); return true; } catch (NumberFormatException ignored) {}\n    return false;\n}","typeGuard":"static boolean isIntegerLike(Object v) {\n    if (v instanceof Number n) return n.intValue() == n.doubleValue();\n    if (v instanceof String s) return s.matches(\"[+-]?(?:0[xX][0-9A-Fa-f]+|\\\\d+)\");\n    return false;\n}","tryCatchPattern":"{\n  \"convert\": {\n    \"field\": \"count\", \"type\": \"integer\",\n    \"on_failure\": [\n      { \"set\": { \"field\": \"ingest.error\", \"value\": \"convert-int\" } },\n      { \"redirect\": { \"pipeline\": \"quarantine\" } }\n    ]\n  }\n}","preventionTips":["For decimal source values, convert to double first then cast to int via a script — Integer.parseInt rejects '1.5'.","Strip currency symbols, whitespace, and locale separators from numeric strings upstream.","Set ignore_missing: true when the field may be absent."],"tags":["ingest","convert","type-coercion","parsing"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T11:17:21.771Z"}