elastic/elasticsearch · error · IllegalArgumentException

time value cannot store values greater than 106751 days

Error message

time value cannot store values greater than 106751 days

What it means

Thrown by TimeValue.timeValueDays when the input exceeds 106751 days. That limit is not arbitrary: 106751.9 days is Long.MAX_VALUE expressed in nanoseconds, and TimeValue internally stores durations convertible to nanoseconds, so any larger value would overflow. The check prevents silent overflow that would otherwise produce a nonsense (possibly negative) duration.

Source

Thrown at libs/core/src/main/java/org/elasticsearch/core/TimeValue.java:89

        return new TimeValue(seconds, TimeUnit.SECONDS);
    }

    public static TimeValue timeValueMinutes(long minutes) {
        if (minutes == 1) {
            // common value, no need to allocate each time
            return ONE_MINUTE;
        }
        return new TimeValue(minutes, TimeUnit.MINUTES);
    }

    public static TimeValue timeValueHours(long hours) {
        return new TimeValue(hours, TimeUnit.HOURS);
    }

    public static TimeValue timeValueDays(long days) {
        // 106751.9 days is Long.MAX_VALUE nanoseconds, so we cannot store 106752 days
        if (days > 106751) {
            throw new IllegalArgumentException("time value cannot store values greater than 106751 days");
        }
        return new TimeValue(days, TimeUnit.DAYS);
    }

    /**
     * @return the {@link TimeValue} object that has the least duration.
     */
    public static TimeValue min(TimeValue time1, TimeValue time2) {
        return time1.compareTo(time2) < 0 ? time1 : time2;
    }

    /**
     * @return the unit used for the this time value, see {@link #duration()}
     */
    public TimeUnit timeUnit() {
        return timeUnit;
    }

View on GitHub (pinned to db6a809a66)

Solutions

  1. Use -1 (TimeValue.MINUS_ONE) to represent infinite/unlimited durations rather than a huge day count.
  2. Reduce the value to a realistic bound (< 106751 days, i.e. ~292 years).
  3. Double-check the unit: ensure you are not passing milliseconds or seconds into a days parameter.
  4. Validate input range before constructing: `if (days > 106751) throw ...`.

Example fix

// before
TimeValue retention = TimeValue.timeValueDays(1_000_000);
// after
TimeValue retention = TimeValue.MINUS_ONE; // or a realistic value
TimeValue retention = TimeValue.timeValueDays(365);
Defensive patterns

Strategy: validation

Validate before calling

static TimeValue safeDays(long days) {
    if (days > 106751) {
        throw new IllegalArgumentException("Days value " + days + " exceeds 106751; use -1 for unlimited.");
    }
    return TimeValue.timeValueDays(days);
}

Type guard

static boolean isStorableDaysValue(long days) {
    return days <= 106751;
}

Try / catch

try {
    TimeValue tv = TimeValue.timeValueDays(days);
} catch (IllegalArgumentException e) {
    if (e.getMessage().contains("106751")) {
        // use -1 to represent unlimited, or cap at the maximum storable value
        return TimeValue.MINUS_ONE;
    }
    throw e;
}

Prevention

When it happens

Trigger: Configuring an index retention or lifecycle interval in days with an absurdly large value (e.g. `365000`). Constructing a TimeValue from a computed `days` long that overflowed. Confusing units (passing milliseconds into a days field).

Common situations: Typo adding extra zeros to a retention period. Settings meant to be infinite that should use -1 instead of a huge number. Unit confusion in conversion code.

Related errors


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