elastic/elasticsearch · error · IllegalArgumentException

dateTimeUnit must be one of {ALLOWED_INTERVALS.keySet()}

Error message

dateTimeUnit must be one of {ALLOWED_INTERVALS.keySet()}

What it means

Thrown by RoundingInfo's constructor (an internal nested class of AutoDateHistogramAggregationBuilder) when the provided Rounding.DateTimeUnit is not a key in ALLOWED_INTERVALS. ALLOWED_INTERVALS keys are the six supported DateTimeUnits (year, month, day, hour, minute, second at the Rounding level). This is primarily an internal/streaming invariant rather than a user-facing validation.

Source

Thrown at modules/aggregations/src/main/java/org/elasticsearch/aggregations/bucket/histogram/AutoDateHistogramAggregationBuilder.java:280

        final int[] innerIntervals;
        final long roughEstimateDurationMillis;
        final String unitAbbreviation;
        final String dateTimeUnit;

        public RoundingInfo(
            Rounding.DateTimeUnit dateTimeUnit,
            ZoneId timeZone,
            long roughEstimateDurationMillis,
            String unitAbbreviation,
            int... innerIntervals
        ) {
            this.rounding = createRounding(dateTimeUnit, timeZone);
            this.roughEstimateDurationMillis = roughEstimateDurationMillis;
            this.unitAbbreviation = unitAbbreviation;
            this.innerIntervals = innerIntervals;
            Objects.requireNonNull(dateTimeUnit, "dateTimeUnit cannot be null");
            if (ALLOWED_INTERVALS.containsKey(dateTimeUnit) == false) {
                throw new IllegalArgumentException("dateTimeUnit must be one of " + ALLOWED_INTERVALS.keySet());
            }
            this.dateTimeUnit = ALLOWED_INTERVALS.get(dateTimeUnit);
        }

        public RoundingInfo(StreamInput in) throws IOException {
            rounding = Rounding.read(in);
            roughEstimateDurationMillis = in.readVLong();
            innerIntervals = in.readIntArray();
            unitAbbreviation = in.readString();
            dateTimeUnit = in.readString();
        }

        @Override
        public void writeTo(StreamOutput out) throws IOException {
            rounding.writeTo(out);
            out.writeVLong(roughEstimateDurationMillis);
            out.writeIntArray(innerIntervals);
            out.writeString(unitAbbreviation);

View on GitHub (pinned to db6a809a66)

Solutions

  1. Ensure all nodes in the cluster run compatible versions (no mixed unsupported units during rolling upgrades).
  2. If extending Rounding.DateTimeUnit in a plugin, register it appropriately or avoid routing it through this constructor.
  3. Align client and server versions so serialized RoundingInfo uses only the allowed units.
Defensive patterns

Strategy: try-catch

Try / catch

try { /* construct / deserialize RoundingInfo */ }
catch (IllegalArgumentException e) {
  if (e.getMessage().contains("dateTimeUnit must be one of")) {
    // log version mismatch, retry against a compatible node
  } else throw e;
}

Prevention

When it happens

Trigger: Constructing RoundingInfo with a DateTimeUnit outside the allowed set — typically only reachable from internal code paths, BWC stream deserialization between mismatched versions, or a direct programmatic invocation with an unsupported unit like a custom Rounding.DateTimeUnit.

Common situations: Rolling upgrades where a node sends a RoundingInfo stream containing a DateTimeUnit the receiving node's ALLOWED_INTERVALS does not contain. Plugin or custom code extending Rounding.DateTimeUnit and passing it to this constructor. Version skew between client and server.

Related errors


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