elastic/elasticsearch · error · IllegalArgumentException
unable to convert [{}] to long
Error message
unable to convert [{}] to long What it means
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.
Source
Thrown at modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ConvertProcessor.java:58
}
return Integer.parseInt(strValue);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("unable to convert [" + value + "] to integer", e);
}
}
},
LONG {
@Override
public Object convert(Object value) {
try {
String strValue = value.toString();
if (strValue.startsWith("0x") || strValue.startsWith("-0x")) {
return Long.decode(strValue);
}
return Long.parseLong(strValue);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("unable to convert [" + value + "] to long", e);
}
}
},
DOUBLE {
@Override
public Object convert(Object value) {
try {
return Double.parseDouble(value.toString());
} catch (NumberFormatException e) {
throw new IllegalArgumentException("unable to convert [" + value + "] to double", e);
}
}
},
FLOAT {
@Override
public Object convert(Object value) {
try {
return Float.parseFloat(value.toString());View on GitHub (pinned to db6a809a66)
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.
Example fix
// before — decimal string cannot be parsed as long
// { "convert": { "field": "bytes", "type": "long" } } // bytes = "1234.0"
//
// after — coerce to double first, then cast
// { "convert": { "field": "bytes", "type": "double" } },
// { "script": { "source": "ctx.bytes = (long) ctx.bytes" } } Defensive patterns
Strategy: validation
Validate before calling
boolean isParsableAsLong(Object v) {
if (v == null) return false;
String s = v.toString();
try { Long.decode(s); return true; } catch (NumberFormatException ignored) {}
try { Long.parseLong(s); return true; } catch (NumberFormatException ignored) {}
return false;
} Type guard
static boolean isLongLike(Object v) {
if (v instanceof Number n) return n.longValue() == n.doubleValue();
if (v instanceof String s) return s.matches("[+-]?(?:0[xX][0-9A-Fa-f]+|\\d+)");
return false;
} Try / catch
{
"convert": {
"field": "bytes", "type": "long",
"on_failure": [
{ "set": { "field": "ingest.error", "value": "convert-long" } },
{ "redirect": { "pipeline": "quarantine" } }
]
}
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- unable to convert [{}] to integer
- unable to convert [{}] to double
- unable to parse URI [${uriString}]
- Illegal escape sequence '\{}'
- Invalid extensions in the CEF event: {}
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/fdb0e3d5e547b0b9.
Report an issue: GitHub.