{"record":{"id":"91a0b1f3d8479d46","repo":"elastic/elasticsearch","slug":"filter-must-not-be-null","errorCode":null,"errorMessage":"[filter] must not be null","messagePattern":"\\[filter\\] must not be null","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/aggregations/src/main/java/org/elasticsearch/aggregations/bucket/adjacency/AdjacencyMatrixAggregator.java","lineNumber":65,"sourceCode":"public class AdjacencyMatrixAggregator extends BucketsAggregator {\n\n    public static final ParseField FILTERS_FIELD = new ParseField(\"filters\");\n\n    protected static class KeyedFilter implements Writeable, ToXContentFragment {\n        private final String key;\n        private final QueryBuilder filter;\n\n        public static final NamedObjectParser<KeyedFilter, String> PARSER = (\n            XContentParser p,\n            String aggName,\n            String name) -> new KeyedFilter(name, parseTopLevelQuery(p));\n\n        public KeyedFilter(String key, QueryBuilder filter) {\n            if (key == null) {\n                throw new IllegalArgumentException(\"[key] must not be null\");\n            }\n            if (filter == null) {\n                throw new IllegalArgumentException(\"[filter] must not be null\");\n            }\n            this.key = key;\n            this.filter = filter;\n        }\n\n        /**\n         * Read from a stream.\n         */\n        public KeyedFilter(StreamInput in) throws IOException {\n            key = in.readString();\n            filter = in.readNamedWriteable(QueryBuilder.class);\n        }\n\n        @Override\n        public void writeTo(StreamOutput out) throws IOException {\n            out.writeString(key);\n            out.writeNamedWriteable(filter);\n        }","sourceCodeStart":47,"sourceCodeEnd":83,"githubUrl":"https://github.com/elastic/elasticsearch/blob/db6a809a667c081ca1dc7500389d26975573215f/modules/aggregations/src/main/java/org/elasticsearch/aggregations/bucket/adjacency/AdjacencyMatrixAggregator.java#L47-L83","documentation":"Thrown by the KeyedFilter constructor (inside AdjacencyMatrixAggregator) when the `filter` (a QueryBuilder) argument is null. Each keyed filter must carry a concrete query; a null query cannot be executed against the index, so construction fails fast.","triggerScenarios":"Constructing `new KeyedFilter(key, null)`. Submitting an adjacency_matrix filter entry whose query body is missing, empty, or unparsable such that the resolved QueryBuilder is null.","commonSituations":"REST requests with a filter object that omits the query clause. Programmatic builders that pass a query variable which is conditionally null. Ingest-time transformation dropping the query.","solutions":["Provide a non-null QueryBuilder (e.g. match_all, term, bool) for every keyed filter.","Default to matchAllQuery() if a filter genuinely should match everything.","Validate each filter's query is non-null before constructing KeyedFilter."],"exampleFix":"// before\nnew KeyedFilter(\"k\", null);\n// after\nnew KeyedFilter(\"k\", QueryBuilders.matchAllQuery());","handlingStrategy":"validation","validationCode":"if (filter == null) {\n  throw new IllegalArgumentException(\"filter query must not be null\");\n}\n// or default: QueryBuilders.matchAllQuery()","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate every filter's QueryBuilder is non-null.","Default to matchAllQuery() when a filter should match everything.","Reject malformed query bodies in REST requests early."],"tags":["aggregations","adjacency-matrix","null-check","query","validation"],"analyzedSha":"db6a809a667c081ca1dc7500389d26975573215f","analyzedAt":"2026-08-12T01:39:14.192Z","schemaVersion":2},"datasetVersion":"2026-08-12T08:17:17.861Z"}