elastic/elasticsearch · error · IllegalArgumentException

ignore value should be a number, found [{}] instead

Error message

ignore value should be a number, found [{}] instead

What it means

Thrown while parsing the comma-separated list of HTTP status codes passed via the RequestOptions 'ignore' parameter. Each token must parse as an Integer; any non-numeric token raises IllegalArgumentException chaining the NumberFormatException. HEAD requests implicitly add 404 to the ignore set beforehand.

Source

Thrown at client/rest/src/main/java/org/elasticsearch/client/RestClient.java:875

        if (ignoreString == null) {
            if (HttpHead.METHOD_NAME.equals(requestMethod)) {
                // 404 never causes error if returned for a HEAD request
                ignoreErrorCodes = Collections.singleton(404);
            } else {
                ignoreErrorCodes = Collections.emptySet();
            }
        } else {
            String[] ignoresArray = ignoreString.split(",");
            ignoreErrorCodes = new HashSet<>();
            if (HttpHead.METHOD_NAME.equals(requestMethod)) {
                // 404 never causes error if returned for a HEAD request
                ignoreErrorCodes.add(404);
            }
            for (String ignoreCode : ignoresArray) {
                try {
                    ignoreErrorCodes.add(Integer.valueOf(ignoreCode));
                } catch (NumberFormatException e) {
                    throw new IllegalArgumentException("ignore value should be a number, found [" + ignoreString + "] instead", e);
                }
            }
        }
        return ignoreErrorCodes;
    }

    private static class ResponseOrResponseException {
        private final Response response;
        private final ResponseException responseException;

        ResponseOrResponseException(Response response) {
            this.response = Objects.requireNonNull(response);
            this.responseException = null;
        }

        ResponseOrResponseException(ResponseException responseException) {
            this.responseException = Objects.requireNonNull(responseException);
            this.response = null;

View on GitHub (pinned to db6a809a66)

Solutions

  1. Provide only integer status codes separated by commas, e.g. "404,500,409".
  2. Trim whitespace and avoid trailing commas in the ignore string.
  3. Use the typed API (RequestOptions.Builder) where available rather than hand-built strings.

Example fix

// before
RequestOptions opts = RequestOptions.DEFAULT.toBuilder()
    .putHeader("Accept", "application/json").build();
Request req = new Request("GET", "/missing");
req.getOptions().toBuilder().addParameter("ignore", "not_found");
// after
RequestOptions opts = RequestOptions.DEFAULT.toBuilder()
    .putHeader("Accept", "application/json").build();
Request req = new Request("GET", "/missing");
req.getOptions().toBuilder().addParameter("ignore", "404");
Defensive patterns

Strategy: validation

Validate before calling

static Set<Integer> parseIgnore(String s) {
    Set<Integer> out = new HashSet<>();
    for (String t : s.split(",")) {
        String v = t.trim();
        if (v.isEmpty()) continue;
        out.add(Integer.parseInt(v)); // throws NumberFormatException -> convert to IllegalArgumentException upstack
    }
    return out;
}

Try / catch

try { RequestOptions b = base.toBuilder().addParameter("ignore", codes).build(); }
catch (IllegalArgumentException e) { /* user-supplied ignore list bad: surface as 400 */ }

Prevention

When it happens

Trigger: Building RequestOptions with setParameter("ignore", "404,500") where one token is not an integer (e.g. "4xx", "", "not_found").

Common situations: Copy-pasting symbolic error names instead of codes; trailing comma producing an empty token; whitespace-only token; misusing the option as a free-form list.

Related errors


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