{"record":{"id":"292fec9c4dc6caf3","repo":"elastic/elasticsearch","slug":"failed-to-parse-setting-with-value-as-a","errorCode":null,"errorMessage":"failed to parse setting [{}] with value [{}] as a time value: unit is missing or unrecognized","messagePattern":"failed to parse setting \\[(.+?)\\] with value \\[(.+?)\\] as a time value: unit is missing or unrecognized","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"libs/core/src/main/java/org/elasticsearch/core/TimeValue.java","lineNumber":404,"sourceCode":"            return new TimeValue(parse(sValue, normalized, \"micros\", settingName), TimeUnit.MICROSECONDS);\n        } else if (normalized.endsWith(\"ms\")) {\n            return TimeValue.timeValueMillis(parse(sValue, normalized, \"ms\", settingName));\n        } else if (normalized.endsWith(\"s\")) {\n            return TimeValue.timeValueSeconds(parse(sValue, normalized, \"s\", settingName));\n        } else if (sValue.endsWith(\"m\")) {\n            // parsing minutes should be case-sensitive as 'M' means \"months\", not \"minutes\"; this is the only special case.\n            return TimeValue.timeValueMinutes(parse(sValue, normalized, \"m\", settingName));\n        } else if (normalized.endsWith(\"h\")) {\n            return TimeValue.timeValueHours(parse(sValue, normalized, \"h\", settingName));\n        } else if (normalized.endsWith(\"d\")) {\n            return new TimeValue(parse(sValue, normalized, \"d\", settingName), TimeUnit.DAYS);\n        } else if (normalized.matches(\"-0*1\")) {\n            return TimeValue.MINUS_ONE;\n        } else if (normalized.matches(\"0+\")) {\n            return TimeValue.ZERO;\n        } else {\n            // Missing units:\n            throw new IllegalArgumentException(\n                \"failed to parse setting [\" + settingName + \"] with value [\" + sValue + \"] as a time value: unit is missing or unrecognized\"\n            );\n        }\n    }\n\n    private static long parse(final String initialInput, final String normalized, final String suffix, String settingName) {\n        final String s = normalized.substring(0, normalized.length() - suffix.length()).trim();\n        try {\n            final long value = Long.parseLong(s);\n            if (value < -1) {\n                // -1 is magic, but reject any other negative values\n                throw new IllegalArgumentException(\n                    \"failed to parse setting [\"\n                        + settingName\n                        + \"] with value [\"\n                        + initialInput\n                        + \"] as a time value: negative durations are not supported\"\n                );","sourceCodeStart":386,"sourceCodeEnd":422,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/libs/core/src/main/java/org/elasticsearch/core/TimeValue.java#L386-L422","documentation":"Thrown by TimeValue.parseTimeValue when the input string has no recognized unit suffix or ends with an unknown suffix. Recognized suffixes are `ms`, `s`, `m`, `h`, `d` (and `micros`, `nanos` for the long overloads). A bare number like `5` or a value like `5x` falls through every suffix check, matches neither the `-0*1` (minus-one) nor `0+` (zero) patterns, and is rejected. The message includes the setting name and raw value for diagnosis.","triggerScenarios":"Writing `refresh_interval: 5` (missing unit) in an index setting. Typing `5sec` instead of `5s`. Using uppercase `5S` (only lowercase is accepted for the case-insensitive suffixes, and `M` is case-sensitive to distinguish minutes from months). Mixing locale-specific decimal separators.","commonSituations":"Operators copy values from other systems (Prometheus `5s`, Java Duration `PT5S`) without translating. YAML auto-coercing `5` to an integer. Docs examples trimmed of the unit. Negative values other than `-1`.","solutions":["Append a recognized unit: `5s`, `500ms`, `10m`, `1h`, `7d`.","Use `-1` for infinite/undefined where the setting allows it.","Use `0` explicitly when you mean zero (do not rely on empty string).","For minutes use lowercase `m`; uppercase `M` is reserved for months and will not parse as minutes."],"exampleFix":"// before\nPUT /my-index/_settings { \"index.refresh_interval\": \"5\" }\n// after\nPUT /my-index/_settings { \"index.refresh_interval\": \"5s\" }","handlingStrategy":"validation","validationCode":"static final Pattern TIME = Pattern.compile(\"-?(?:0|[1-9][0-9]*)(?:ns|micros|ms|s|m|h|d)\");\nstatic boolean isParsableTimeValue(String v) {\n    if (v == null) return false;\n    if (v.matches(\"-0*1\") || v.matches(\"0+\")) return true;\n    return TIME.matcher(v).matches();\n}","typeGuard":"static boolean looksLikeTimeValue(String v) {\n    if (v == null || v.isBlank()) return false;\n    String n = v.trim().toLowerCase(Locale.ROOT);\n    return n.matches(\"-?(?:0|[1-9][0-9]*)(ns|micros|ms|s|m|h|d)\")\n        || n.matches(\"-0*1\") || n.matches(\"0+\");\n}","tryCatchPattern":"try {\n    TimeValue tv = TimeValue.parseTimeValue(raw, null, settingName);\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"unit is missing or unrecognized\")) {\n        // prompt user for the correct unit (s/ms/m/h/d) and retry\n    } else throw e;\n}","preventionTips":["Always suffix time settings with a unit: s, ms, m, h, d.","Remember 'M' means months and is not accepted; use lowercase 'm' for minutes.","Use -1 for infinite where allowed; use 0 explicitly for zero.","Validate time-value strings at the configuration boundary before sending to Elasticsearch."],"tags":["core","time-value","parsing","settings","configuration","units"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T12:17:08.281Z"}