{"record":{"id":"a414e121b21fb20d","repo":"elsa-workflows/elsa-core","slug":"no-declared-index-exists-for-storage-unit-query-storageunit","errorCode":null,"errorMessage":"No declared index exists for storage unit '{query.StorageUnit}' and fields '{string.Join(\", \", fields.Order())}'.","messagePattern":"No declared index exists for storage unit '(.+?)' and fields '(.+?)'\\.","errorType":"validation","errorClass":"DocumentQueryNotIndexedException","httpStatus":null,"severity":"error","filePath":"src/modules/Elsa.Persistence.VNext/Document/DocumentIndexMatcher.cs","lineNumber":11,"sourceCode":"namespace Elsa.Persistence.VNext.Document;\n\npublic static class DocumentIndexMatcher\n{\n    public static DocumentIndex FindMatchingIndex(DocumentCollection collection, DocumentQuery query)\n    {\n        var filterFields = query.Filters.Keys.Order(StringComparer.Ordinal).ToArray();\n        var index = collection.Indexes.SingleOrDefault(x => x.Fields.Order(StringComparer.Ordinal).SequenceEqual(filterFields, StringComparer.Ordinal));\n\n        if (index is null)\n            throw new DocumentQueryNotIndexedException(query.StorageUnit, filterFields);\n\n        return index;\n    }\n}\n","sourceCodeStart":1,"sourceCodeEnd":16,"githubUrl":"https://github.com/elsa-workflows/elsa-core/blob/fe9217bdfa0e27f0e09e45006eb6898f616e513d/src/modules/Elsa.Persistence.VNext/Document/DocumentIndexMatcher.cs#L1-L16","documentation":"DocumentIndexMatcher.FindMatchingIndex requires that a document collection declares an index whose exact ordered field list matches the sorted filter fields of the query. If no such single index exists, it throws DocumentQueryNotIndexedException, telling you the query cannot be executed against the declared indexes.","triggerScenarios":"Executing a DocumentQuery whose filter fields do not exactly equal (as an ordered set, ordinal-compared) the Fields of any index in collection.Indexes — e.g. filtering on Status alone when only a composite (Status, Name) index is declared, or on fields in a different order than declared.","commonSituations":"Changing query filters after indexes were designed; forgetting to declare an index for a new query; case or ordering differences between filter keys and index fields.","solutions":["Add a matching index to the storage unit whose Fields exactly match the query filter fields (ordinal-ordered).","Adjust the query filters to exactly match an existing declared index.","Declare a composite index covering all filtered fields in the same ordinal order the matcher compares."],"exampleFix":"// before\n// query filters: { Status, Name } but only index on [Status] exists\nbuilder.Table(\"WorkflowInstances\", t => t.HasIndex(\"IX_Status\", i => i.Fields(\"Status\")));\n// after\nbuilder.Table(\"WorkflowInstances\", t => t.HasIndex(\"IX_Status_Name\", i => i.Fields(\"Status\", \"Name\")));","handlingStrategy":"validation","validationCode":"var filterFields = query.Filters.Keys.Order(StringComparer.Ordinal).ToArray();\nvar indexed = collection.Indexes.Any(i => i.Fields.Order(StringComparer.Ordinal).SequenceEqual(filterFields, StringComparer.Ordinal));\nif (!indexed) throw new InvalidOperationException(\"No index covers query filter fields.\");","typeGuard":null,"tryCatchPattern":"try { var idx = DocumentIndexMatcher.FindMatchingIndex(collection, query); }\ncatch (DocumentQueryNotIndexedException ex) { /* add index or rewrite query */ }","preventionTips":["Design indexes alongside every query filter combination.","Compare fields ordinal-ordered, exactly as the matcher does.","Add a test asserting each production query has a covering index."],"tags":["document-store","index","query","persistence"],"backgroundTag":"index-not-found","analyzedSha":"fe9217bdfa0e27f0e09e45006eb6898f616e513d","analyzedAt":"2026-09-13T20:32:34.702Z","contentChangedAt":"2026-09-13T20:32:34.702Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}