elastic/elasticsearch · error · IllegalArgumentException
failed to parse setting [{}] with value [{}] as a time value
Error message
failed to parse setting [{}] with value [{}] as a time value: negative durations are not supported What it means
Thrown by TimeValue.parse when a setting's numeric component parses as a valid long but is less than -1. The value -1 is reserved as a magic sentinel (typically meaning 'disabled' or 'unbounded'); every other negative duration is rejected because negative time has no meaningful interpretation for a timeout or interval. The error names the setting and echoes the original (un-normalized) input so the offending config line is identifiable.
Source
Thrown at libs/core/src/main/java/org/elasticsearch/core/TimeValue.java:416
} else if (normalized.matches("-0*1")) {
return TimeValue.MINUS_ONE;
} else if (normalized.matches("0+")) {
return TimeValue.ZERO;
} else {
// Missing units:
throw new IllegalArgumentException(
"failed to parse setting [" + settingName + "] with value [" + sValue + "] as a time value: unit is missing or unrecognized"
);
}
}
private static long parse(final String initialInput, final String normalized, final String suffix, String settingName) {
final String s = normalized.substring(0, normalized.length() - suffix.length()).trim();
try {
final long value = Long.parseLong(s);
if (value < -1) {
// -1 is magic, but reject any other negative values
throw new IllegalArgumentException(
"failed to parse setting ["
+ settingName
+ "] with value ["
+ initialInput
+ "] as a time value: negative durations are not supported"
);
}
return value;
} catch (final NumberFormatException e) {
try {
@SuppressWarnings("unused")
final double ignored = Double.parseDouble(s);
throw new IllegalArgumentException("failed to parse [" + initialInput + "], fractional time values are not supported", e);
} catch (final NumberFormatException ignored) {
throw new IllegalArgumentException("failed to parse [" + initialInput + "]", e);
}
}
}View on GitHub (pinned to db6a809a66)
Solutions
- Set the value to a positive duration (e.g. "30s", "5m") or to -1 if the setting treats -1 as disabled/unbounded.
- If the value comes from a computed variable, clamp it: value = Math.max(-1, computed) before formatting the string.
- Audit the offending setting name in the error message against elasticsearch.yml or the index/cluster settings API to locate the bad input.
- If you genuinely need 'no timeout', use -1 (and confirm the specific setting honors the -1 sentinel — not all do).
Example fix
// before index.cache.query.size: -5m // after index.cache.query.size: -1 // -1 = disabled; or a positive duration like 10m
Defensive patterns
Strategy: validation
Validate before calling
// Validate a candidate time-value string before passing to TimeValue.parseTimeValue
private static final Pattern TV = Pattern.compile("^(?:-1|-?\\d+)([a-z\\u00b5]+)$");
void check(String s, String setting) {
Matcher m = TV.matcher(s.toLowerCase(Locale.ROOT).trim());
if (!m.matches()) throw new IllegalArgumentException("bad " + setting + ": " + s);
if (!s.equals("-1")) {
long n = Long.parseLong(m.group(0).replaceAll("[a-z\\u00b5]+$", ""));
if (n < -1) throw new IllegalArgumentException("negative duration not allowed: " + s);
}
} Type guard
// Narrow string inputs known to be safe for TimeValue
static boolean isAcceptableDuration(String s) {
if (s == null) return false;
String n = s.trim().toLowerCase(Locale.ROOT);
return n.equals("-1") || n.matches("0+") || n.matches("\\d+(ns|us|micros|ms|s|m|h|d)");
} Try / catch
try {
TimeValue tv = TimeValue.parseTimeValue(raw, setting);
} catch (IllegalArgumentException e) {
// surface to the user/config layer with the setting name; do not silently default
throw new ConfigException("Invalid value for [" + setting + "]: " + raw, e);
} Prevention
- Always specify a unit suffix (s, ms, m, h, d) — never a bare negative number.
- Treat -1 as the only legal negative; clamp computed durations to Math.max(-1, value).
- Validate user/config time strings with a regex before forwarding to TimeValue.
- In tests, assert that settings derived from formulas can never underflow below -1.
When it happens
Trigger: Calling TimeValue.parseTimeValue (or any setting parser that delegates to it) with input like "-5s", "-100ms", "-2h", or "-50". Produced when an index setting, cluster setting, or transport timeout is set to a negative number other than -1. Concretely fires at TimeValue.java:416 after Long.parseLong succeeds with value < -1.
Common situations: A user sets a timeout setting (e.g. search.default_search_timeout, transport.connect_timeout) to a negative value by mistake, or a formula/variable that underflows to negative. Copy-pasting a value meant for a different unit. Tooling that injects computed durations without clamping to a minimum.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- failed to parse [{}], fractional time values are not support
- failed to parse [{}]
- failed to parse setting [{}] with value [{}] as a time value
- Failed to parse value [{}] as only [true] or [false] are all
- duration cannot be negative, was given [{}]
AI-assisted analysis of elastic/elasticsearch@db6a809a66 (2026-08-12).
Data as JSON: /api/errors/619003cb59c65fd6.
Report an issue: GitHub.