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

  1. Pre-clean the value to plain ASCII digits (with optional leading '+'/'-').
  2. For decimal values, route through type: double then cast to long via a script.
  3. Use ignore_missing: true if the field is sometimes absent; filter empty strings upstream.
  4. 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

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


AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12). Data as JSON: /api/errors/fdb0e3d5e547b0b9. Report an issue: GitHub.