{"record":{"id":"bd22cf7f5772b1ab","repo":"elastic/elasticsearch","slug":"datetimeunit-must-be-one-of-allowed-intervals-key","errorCode":null,"errorMessage":"dateTimeUnit must be one of {ALLOWED_INTERVALS.keySet()}","messagePattern":"dateTimeUnit must be one of (.+?)","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/aggregations/src/main/java/org/elasticsearch/aggregations/bucket/histogram/AutoDateHistogramAggregationBuilder.java","lineNumber":280,"sourceCode":"        final int[] innerIntervals;\n        final long roughEstimateDurationMillis;\n        final String unitAbbreviation;\n        final String dateTimeUnit;\n\n        public RoundingInfo(\n            Rounding.DateTimeUnit dateTimeUnit,\n            ZoneId timeZone,\n            long roughEstimateDurationMillis,\n            String unitAbbreviation,\n            int... innerIntervals\n        ) {\n            this.rounding = createRounding(dateTimeUnit, timeZone);\n            this.roughEstimateDurationMillis = roughEstimateDurationMillis;\n            this.unitAbbreviation = unitAbbreviation;\n            this.innerIntervals = innerIntervals;\n            Objects.requireNonNull(dateTimeUnit, \"dateTimeUnit cannot be null\");\n            if (ALLOWED_INTERVALS.containsKey(dateTimeUnit) == false) {\n                throw new IllegalArgumentException(\"dateTimeUnit must be one of \" + ALLOWED_INTERVALS.keySet());\n            }\n            this.dateTimeUnit = ALLOWED_INTERVALS.get(dateTimeUnit);\n        }\n\n        public RoundingInfo(StreamInput in) throws IOException {\n            rounding = Rounding.read(in);\n            roughEstimateDurationMillis = in.readVLong();\n            innerIntervals = in.readIntArray();\n            unitAbbreviation = in.readString();\n            dateTimeUnit = in.readString();\n        }\n\n        @Override\n        public void writeTo(StreamOutput out) throws IOException {\n            rounding.writeTo(out);\n            out.writeVLong(roughEstimateDurationMillis);\n            out.writeIntArray(innerIntervals);\n            out.writeString(unitAbbreviation);","sourceCodeStart":262,"sourceCodeEnd":298,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/aggregations/src/main/java/org/elasticsearch/aggregations/bucket/histogram/AutoDateHistogramAggregationBuilder.java#L262-L298","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Ensure all nodes in the cluster run compatible versions (no mixed unsupported units during rolling upgrades).","If extending Rounding.DateTimeUnit in a plugin, register it appropriately or avoid routing it through this constructor.","Align client and server versions so serialized RoundingInfo uses only the allowed units."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try { /* construct / deserialize RoundingInfo */ }\ncatch (IllegalArgumentException e) {\n  if (e.getMessage().contains(\"dateTimeUnit must be one of\")) {\n    // log version mismatch, retry against a compatible node\n  } else throw e;\n}","preventionTips":["Keep cluster nodes on compatible versions during rolling upgrades.","Do not route unsupported Rounding.DateTimeUnit values through RoundingInfo.","Align plugin Rounding extensions with the allowed intervals."],"tags":["aggregations","auto-date-histogram","internal","bwc","rounding"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}