elastic/elasticsearch · error · IllegalArgumentException

unable to convert [{}] to integer

Error message

unable to convert [{}] to integer

What it means

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.

Source

Thrown at modules/ingest-common/src/main/java/org/elasticsearch/ingest/common/ConvertProcessor.java:43

/**
 * Processor that converts fields content to a different type. Supported types are: integer, float, boolean and string.
 * Throws exception if the field is not there or the conversion fails.
 */
public final class ConvertProcessor extends AbstractProcessor {

    enum Type {
        INTEGER {
            @Override
            public Object convert(Object value) {
                try {
                    String strValue = value.toString();
                    if (strValue.startsWith("0x") || strValue.startsWith("-0x")) {
                        return Integer.decode(strValue);
                    }
                    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);
                }
            }
        },

View on GitHub (pinned to db6a809a66)

Solutions

  1. If the value is decimal, convert via a two-step: type: double then a script to cast, or pre-round.
  2. Strip currency symbols, whitespace, and thousands separators before the convert processor.
  3. Set ignore_missing: true if the field is sometimes absent, or filter empty strings upstream.
  4. Use on_failure to quarantine unconvertible values.

Example fix

// before — decimal string cannot be parsed as integer
//   { "convert": { "field": "count", "type": "integer" } }  // count = "1.5"
//
// after — accept decimal, then truncate via script
//   { "convert": { "field": "count", "type": "double" } },
//   { "script": { "source": "ctx.count = (int) ctx.count" } }
Defensive patterns

Strategy: validation

Validate before calling

boolean isParsableAsInteger(Object v) {
    if (v == null) return false;
    String s = v.toString();
    try { Integer.decode(s); return true; } catch (NumberFormatException ignored) {}
    try { Integer.parseInt(s); return true; } catch (NumberFormatException ignored) {}
    return false;
}

Type guard

static boolean isIntegerLike(Object v) {
    if (v instanceof Number n) return n.intValue() == n.doubleValue();
    if (v instanceof String s) return s.matches("[+-]?(?:0[xX][0-9A-Fa-f]+|\\d+)");
    return false;
}

Try / catch

{
  "convert": {
    "field": "count", "type": "integer",
    "on_failure": [
      { "set": { "field": "ingest.error", "value": "convert-int" } },
      { "redirect": { "pipeline": "quarantine" } }
    ]
  }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


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