elastic/elasticsearch · error · IllegalArgumentException

Failed to parse value [{}] as only [true] or [false] are all

Error message

Failed to parse value [{}] as only [true] or [false] are allowed.

What it means

Thrown by Booleans.parseBoolean (the core library used across all of Elasticsearch) when the input is not exactly `true` or `false` (case-sensitive). Unlike permissive parsers, Elasticsearch's boolean parser intentionally rejects synonyms like `yes`, `1`, `on`, `enabled` to keep settings unambiguous. This is the canonical boolean parse error for YAML/JSON settings, index settings, and cluster settings.

Source

Thrown at libs/core/src/main/java/org/elasticsearch/core/Booleans.java:63

    public static boolean isBoolean(String value) {
        return isFalse(value) || isTrue(value);
    }

    /**
     * Parses a string representation of a boolean value to <code>boolean</code>.
     *
     * @return <code>true</code> iff the provided value is "true". <code>false</code> iff the provided value is "false".
     * @throws IllegalArgumentException if the string cannot be parsed to boolean.
     */
    public static boolean parseBoolean(String value) {
        if (isFalse(value)) {
            return false;
        }
        if (isTrue(value)) {
            return true;
        }
        throw new IllegalArgumentException("Failed to parse value [" + value + "] as only [true] or [false] are allowed.");
    }

    private static boolean hasText(CharSequence str) {
        if (str == null || str.length() == 0) {
            return false;
        }
        int strLen = str.length();
        for (int i = 0; i < strLen; i++) {
            if (Character.isWhitespace(str.charAt(i)) == false) {
                return true;
            }
        }
        return false;
    }

    /**
     *
     * @param value text to parse.

View on GitHub (pinned to db6a809a66)

Solutions

  1. Use exactly `true` or `false` (lowercase, no quotes in YAML, double-quoted in JSON).
  2. Normalize upstream: `value = bool_val ? "true" : "false"` before sending to Elasticsearch.
  3. For numeric sources, map explicitly: `bool_str = n == 0 ? "false" : "true"`.

Example fix

// before
PUT /my-index/_settings { "index.blocks.read_only": "yes" }
// after
PUT /my-index/_settings { "index.blocks.read_only": "true" }
Defensive patterns

Strategy: validation

Validate before calling

static boolean parseBoolStrict(String v) {
    if ("true".equals(v)) return true;
    if ("false".equals(v)) return false;
    throw new IllegalArgumentException("Expected 'true' or 'false', got: " + v);
}

Type guard

static boolean isElasticsearchBoolean(String v) {
    return "true".equals(v) || "false".equals(v);
}

Try / catch

try {
    boolean b = Booleans.parseBoolean(rawValue);
} catch (IllegalArgumentException e) {
    // surface to the user with the setting name; suggest the canonical form
    throw new IllegalArgumentException("Setting " + name + " must be 'true' or 'false'", e);
}

Prevention

When it happens

Trigger: Supplying a setting value of `yes`, `1`, `on`, `True`, `FALSE` (wrong case), or any non-canonical token to a boolean setting. Reading booleans from external systems that use 0/1 or yes/no conventions without normalizing.

Common situations: Migrating configs from other systems (Logstash, Fluentd) that accept `yes`/`no`. JSON produced by languages whose boolean serialization differs. Operators writing YAML from memory assuming 1/0 works.

Understand the failure class

Related errors


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