{"record":{"id":"68d3c5ffdc1f42d1","repo":"elastic/elasticsearch","slug":"buckets-must-be-greater-than-0-for-name","errorCode":null,"errorMessage":"buckets must be greater than 0 for [{name}]","messagePattern":"buckets must be greater than 0 for \\[(.+?)\\]","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/aggregations/src/main/java/org/elasticsearch/aggregations/bucket/histogram/AutoDateHistogramAggregationBuilder.java","lineNumber":181,"sourceCode":"    }\n\n    public String getMinimumIntervalExpression() {\n        return minimumIntervalExpression;\n    }\n\n    public AutoDateHistogramAggregationBuilder setMinimumIntervalExpression(String minimumIntervalExpression) {\n        if (minimumIntervalExpression != null && ALLOWED_INTERVALS.containsValue(minimumIntervalExpression) == false) {\n            throw new IllegalArgumentException(\n                MINIMUM_INTERVAL_FIELD.getPreferredName() + \" must be one of [\" + ALLOWED_INTERVALS.values() + \"]\"\n            );\n        }\n        this.minimumIntervalExpression = minimumIntervalExpression;\n        return this;\n    }\n\n    public AutoDateHistogramAggregationBuilder setNumBuckets(int numBuckets) {\n        if (numBuckets <= 0) {\n            throw new IllegalArgumentException(NUM_BUCKETS_FIELD.getPreferredName() + \" must be greater than 0 for [\" + name + \"]\");\n        }\n        this.numBuckets = numBuckets;\n        return this;\n    }\n\n    @Override\n    public BucketCardinality bucketCardinality() {\n        return BucketCardinality.MANY;\n    }\n\n    @Override\n    protected ValuesSourceAggregatorFactory innerBuild(\n        AggregationContext context,\n        ValuesSourceConfig config,\n        AggregatorFactory parent,\n        Builder subFactoriesBuilder\n    ) throws IOException {\n        AutoDateHistogramAggregatorSupplier aggregatorSupplier = context.getValuesSourceRegistry().getAggregator(REGISTRY_KEY, config);","sourceCodeStart":163,"sourceCodeEnd":199,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/aggregations/src/main/java/org/elasticsearch/aggregations/bucket/histogram/AutoDateHistogramAggregationBuilder.java#L163-L199","documentation":"Thrown by AutoDateHistogramAggregationBuilder.setNumBuckets when numBuckets is <= 0. The auto_date_histogram aggregation requires a positive target bucket count because it dynamically sizes rounding intervals to produce approximately that many buckets; zero or negative is meaningless.","triggerScenarios":"Calling setNumBuckets(0) or setNumBuckets(-1). Submitting a REST request with `\"buckets\": 0` or a negative value. Defaulting from an unset/zero-valued configuration variable.","commonSituations":"Configuration driven by a variable that defaults to 0. User input parsed as integer without a positivity check. Tests passing boundary values.","solutions":["Set buckets to a positive integer (the default is 10).","Validate configuration values are >= 1 before constructing the aggregation.","Coerce zero/negative to the default if the value is optional."],"exampleFix":"// before\n{\"auto_date_histogram\":{\"field\":\"@timestamp\",\"buckets\":0}}\n// after\n{\"auto_date_histogram\":{\"field\":\"@timestamp\",\"buckets\":10}}","handlingStrategy":"validation","validationCode":"if (numBuckets <= 0) {\n  throw new IllegalArgumentException(\"buckets must be > 0\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default computed bucket counts to a positive integer (e.g. 10).","Validate user-supplied configuration for positivity.","Treat zero as unset and fall back to the default."],"tags":["aggregations","auto-date-histogram","validation","bounds"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}