{"record":{"id":"a8dcad4901ad77f2","repo":"elastic/elasticsearch","slug":"failed-to-parse-value-as-only-true-or-fals-a8dcad","errorCode":null,"errorMessage":"Failed to parse value [{}] as only [true] or [false] are allowed.","messagePattern":"Failed to parse value \\[(.+?)\\] as only \\[true\\] or \\[false\\] are allowed\\.","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"libs/core/src/main/java/org/elasticsearch/core/Booleans.java","lineNumber":63,"sourceCode":"\n    public static boolean isBoolean(String value) {\n        return isFalse(value) || isTrue(value);\n    }\n\n    /**\n     * Parses a string representation of a boolean value to <code>boolean</code>.\n     *\n     * @return <code>true</code> iff the provided value is \"true\". <code>false</code> iff the provided value is \"false\".\n     * @throws IllegalArgumentException if the string cannot be parsed to boolean.\n     */\n    public static boolean parseBoolean(String value) {\n        if (isFalse(value)) {\n            return false;\n        }\n        if (isTrue(value)) {\n            return true;\n        }\n        throw new IllegalArgumentException(\"Failed to parse value [\" + value + \"] as only [true] or [false] are allowed.\");\n    }\n\n    private static boolean hasText(CharSequence str) {\n        if (str == null || str.length() == 0) {\n            return false;\n        }\n        int strLen = str.length();\n        for (int i = 0; i < strLen; i++) {\n            if (Character.isWhitespace(str.charAt(i)) == false) {\n                return true;\n            }\n        }\n        return false;\n    }\n\n    /**\n     *\n     * @param value text to parse.","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/libs/core/src/main/java/org/elasticsearch/core/Booleans.java#L45-L81","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Use exactly `true` or `false` (lowercase, no quotes in YAML, double-quoted in JSON).","Normalize upstream: `value = bool_val ? \"true\" : \"false\"` before sending to Elasticsearch.","For numeric sources, map explicitly: `bool_str = n == 0 ? \"false\" : \"true\"`."],"exampleFix":"// before\nPUT /my-index/_settings { \"index.blocks.read_only\": \"yes\" }\n// after\nPUT /my-index/_settings { \"index.blocks.read_only\": \"true\" }","handlingStrategy":"validation","validationCode":"static boolean parseBoolStrict(String v) {\n    if (\"true\".equals(v)) return true;\n    if (\"false\".equals(v)) return false;\n    throw new IllegalArgumentException(\"Expected 'true' or 'false', got: \" + v);\n}","typeGuard":"static boolean isElasticsearchBoolean(String v) {\n    return \"true\".equals(v) || \"false\".equals(v);\n}","tryCatchPattern":"try {\n    boolean b = Booleans.parseBoolean(rawValue);\n} catch (IllegalArgumentException e) {\n    // surface to the user with the setting name; suggest the canonical form\n    throw new IllegalArgumentException(\"Setting \" + name + \" must be 'true' or 'false'\", e);\n}","preventionTips":["Always emit `true`/`false` (lowercase) from generators and migration scripts.","Validate config values with Booleans.isTrue/isFalse before sending to Elasticsearch.","Document that Elasticsearch rejects synonyms like yes/no/1/0 to set expectations."],"tags":["core","boolean","parsing","settings","configuration"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}