{"record":{"id":"fdb0e3d5e547b0b9","repo":"elastic/elasticsearch","slug":"unable-to-convert-to-long","errorCode":null,"errorMessage":"unable to convert [{}] to long","messagePattern":"unable to convert \\[(.+?)\\] to long","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ConvertProcessor.java","lineNumber":58,"sourceCode":"                    }\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        },\n        DOUBLE {\n            @Override\n            public Object convert(Object value) {\n                try {\n                    return Double.parseDouble(value.toString());\n                } catch (NumberFormatException e) {\n                    throw new IllegalArgumentException(\"unable to convert [\" + value + \"] to double\", e);\n                }\n            }\n        },\n        FLOAT {\n            @Override\n            public Object convert(Object value) {\n                try {\n                    return Float.parseFloat(value.toString());","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ConvertProcessor.java#L40-L76","documentation":"ConvertProcessor.Type.LONG.convert wraps NumberFormatException from Long.parseLong (or Long.decode for hex prefixes) with the offending value. Behaves like 1117 but for the long type, so it accepts a wider numeric range and the same hex prefix rules. Decimal notation is still rejected by parseLong.","triggerScenarios":"convert processor with type: long on a value like 'abc', '1.5e3', 'true', '', or malformed hex like '0xZZ.Z'. Multi-valued fields fail on the first unparseable element.","commonSituations":"Same family as 1117: decimal values where integer-only parsing is expected; locale-specific separators; embedded whitespace; currency symbols; scientific notation that Long.parseLong rejects.","solutions":["Pre-clean the value to plain ASCII digits (with optional leading '+'/'-').","For decimal values, route through type: double then cast to long via a script.","Use ignore_missing: true if the field is sometimes absent; filter empty strings upstream.","Quarantine failures via on_failure."],"exampleFix":"// before — decimal string cannot be parsed as long\n//   { \"convert\": { \"field\": \"bytes\", \"type\": \"long\" } }  // bytes = \"1234.0\"\n//\n// after — coerce to double first, then cast\n//   { \"convert\": { \"field\": \"bytes\", \"type\": \"double\" } },\n//   { \"script\": { \"source\": \"ctx.bytes = (long) ctx.bytes\" } }","handlingStrategy":"validation","validationCode":"boolean isParsableAsLong(Object v) {\n    if (v == null) return false;\n    String s = v.toString();\n    try { Long.decode(s); return true; } catch (NumberFormatException ignored) {}\n    try { Long.parseLong(s); return true; } catch (NumberFormatException ignored) {}\n    return false;\n}","typeGuard":"static boolean isLongLike(Object v) {\n    if (v instanceof Number n) return n.longValue() == 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\": \"bytes\", \"type\": \"long\",\n    \"on_failure\": [\n      { \"set\": { \"field\": \"ingest.error\", \"value\": \"convert-long\" } },\n      { \"redirect\": { \"pipeline\": \"quarantine\" } }\n    ]\n  }\n}","preventionTips":["Long.parseLong rejects decimals — pre-cast via double for fractional inputs.","Strip locale-specific thousands separators (',') before the convert processor.","Use ignore_missing: true for fields that may be absent."],"tags":["ingest","convert","type-coercion","parsing"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:31:55.035Z"}