Firestore throws this error when your query combines multiple filters or sorting without a pre-built composite index. Create the missing index via the Firebase Console link in the error message or use the Firebase CLI.
This error occurs when you attempt a complex Firestore query that combines filtering (where clauses) with sorting (orderBy), but no composite index exists to support it. Firestore automatically creates single-field indexes, but composite indexes—which cover multiple fields—must be created manually because of the large number of possible field combinations. When Firestore encounters a query it cannot execute, it returns an error with a direct link to create the required index.
When you encounter the error, check your browser console or Firebase SDK logs. The error message includes a direct link (usually starting with `https://console.firebase.google.com/...`). Click this link and the Firebase Console will automatically populate the index configuration based on your query.In the Firebase Console, navigate to Firestore Database > Indexes > Composite. The index configuration should be pre-filled with your collection name and field definitions. Review the fields and their sort order (Ascending/Descending), then click Create Index. Building the index typically takes a few minutes depending on your data size.
Wait for the index status to change from "Building" to "Enabled". You can monitor progress in the Composite Indexes tab. Once enabled, your query will execute successfully.
If you have multiple indexes to create, use the Firebase CLI:
firebase init firestoreThis generates a firestore.indexes.json file in your project. Edit it to define all your composite indexes:
{
"indexes": [
{
"collectionGroup": "posts",
"queryScope": "Collection",
"fields": [
{ "fieldPath": "status", "order": "ASCENDING" },
{ "fieldPath": "createdAt", "order": "DESCENDING" }
]
}
]
}Then deploy:
firebase deploy --only firestore:indexesAfter the index is enabled, run your query again. It should now execute without the composite index error. If using the SDK, you do not need to change your code—Firestore will automatically use the new index.
Index Planning: Firestore has a limit of 200 composite indexes per database. Plan your queries to reuse indexes where possible. For subcollections with the same name across different parent documents, Firestore can share a single index.
Index Merging: For queries with multiple equality (==) clauses, Firestore can sometimes merge existing single-field indexes. However, queries combining range filters (>, <, >=, <=) with orderBy on different fields always require a dedicated composite index.
Performance Consideration: Composite indexes improve query performance for complex searches but add write latency. Index creation is asynchronous and may take time on large collections. Plan index creation before deploying to production.
messaging/UNSPECIFIED_ERROR: No additional information available
How to fix "messaging/UNSPECIFIED_ERROR: No additional information available" in Firebase Cloud Messaging
App Check: reCAPTCHA Score Too Low
App Check reCAPTCHA Score Too Low
storage/invalid-url: Invalid URL format for Cloud Storage reference
How to fix invalid URL format in Firebase Cloud Storage
auth/missing-uid: User ID identifier required
How to fix "auth/missing-uid: User ID identifier required" in Firebase
auth/invalid-argument: Invalid parameter passed to method
How to fix "auth/invalid-argument: Invalid parameter passed to method" in Firebase