{"record":{"id":"19b8ade06be0c04b","repo":"elastic/elasticsearch","slug":"number-of-filters-is-too-large-must-be-less-than","errorCode":null,"errorMessage":"Number of filters is too large, must be less than or equal to: [${maxFilters}] but was [${filters.size()}].  You can increase this limit by scaling up your java heap","messagePattern":"Number of filters is too large, must be less than or equal to: \\[(.+?)\\] but was \\[(.+?)\\]\\.  You can increase this limit by scaling up your java heap","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/aggregations/src/main/java/org/elasticsearch/aggregations/bucket/adjacency/AdjacencyMatrixAggregationBuilder.java","lineNumber":207,"sourceCode":"        boolean modified = false;\n        List<KeyedFilter> rewrittenFilters = new ArrayList<>(filters.size());\n        for (KeyedFilter kf : filters) {\n            QueryBuilder rewritten = Rewriteable.rewrite(kf.filter(), queryRewriteContext);\n            modified = modified || rewritten != kf.filter();\n            rewrittenFilters.add(new KeyedFilter(kf.key(), rewritten));\n        }\n        if (modified) {\n            return new AdjacencyMatrixAggregationBuilder(name).separator(separator).setFiltersAsList(rewrittenFilters);\n        }\n        return this;\n    }\n\n    @Override\n    protected AggregatorFactory doBuild(AggregationContext context, AggregatorFactory parent, Builder subFactoriesBuilder)\n        throws IOException {\n        int maxFilters = IndexSearcher.getMaxClauseCount();\n        if (filters.size() > maxFilters) {\n            throw new IllegalArgumentException(\n                \"Number of filters is too large, must be less than or equal to: [\"\n                    + maxFilters\n                    + \"] but was [\"\n                    + filters.size()\n                    + \"].  \"\n                    + \"You can increase this limit by scaling up your java heap\"\n            );\n        }\n        return new AdjacencyMatrixAggregatorFactory(name, filters, separator, context, parent, subFactoriesBuilder, metadata);\n    }\n\n    @Override\n    public BucketCardinality bucketCardinality() {\n        return BucketCardinality.MANY;\n    }\n\n    @Override\n    protected XContentBuilder internalXContent(XContentBuilder builder, Params params) throws IOException {","sourceCodeStart":189,"sourceCodeEnd":225,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/aggregations/src/main/java/org/elasticsearch/aggregations/bucket/adjacency/AdjacencyMatrixAggregationBuilder.java#L189-L225","documentation":"Thrown by AdjacencyMatrixAggregationBuilder.doBuild when the number of filters exceeds IndexSearcher.getMaxClauseCount() (default 1024). The adjacency_matrix aggregation creates N boolean clauses (one per filter plus pair combinations), so the count is bounded by the same limit that protects boolean queries from clause explosion. The message suggests scaling heap because the limit is often raised via JVM/system configuration.","triggerScenarios":"Building an adjacency_matrix aggregation with more than `indices.query.bool.max_clause_count` filters (default 1024). Submitting a request with a dynamically generated filters map that grows past the limit.","commonSituations":"Analyzing co-occurrence across many categories (e.g. thousands of tags, topics, or segments). Auto-generated aggregations from user-selected facets. Environments where the max_clause_count setting has not been tuned for heavy boolean workloads.","solutions":["Reduce the number of filters to at or below the current max_clause_count (default 1024).","Raise the limit via the setting `indices.query.bool.max_clause_count` on each node — note this requires adequate heap and increases memory pressure on boolean queries cluster-wide.","Pre-filter to the most significant categories before building the adjacency_matrix.","Consider sampling or a different aggregation strategy if the cardinality is genuinely very high."],"exampleFix":"// before: 2000 filters\n// after: raise the limit in elasticsearch.yml\nindices.query.bool.max_clause_count: 4096\n// and/or reduce filters to the top-N by frequency","handlingStrategy":"validation","validationCode":"int max = org.apache.lucene.search.IndexSearcher.getMaxClauseCount();\nif (filters.size() > max) {\n  throw new IllegalArgumentException(\"too many filters (\" + filters.size() + \" > \" + max + \")\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check filters.size() against indices.query.bool.max_clause_count before building.","Pre-select the top-N categories to keep filter counts bounded.","Raise max_clause_count only with corresponding heap headroom."],"tags":["aggregations","adjacency-matrix","limits","max-clause-count","performance"],"backgroundTag":null,"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-13T09:17:06.757Z"}