Short answer
A query that combines a filter on one field with a sort or range on another needs a composite index, and Firestore doesn’t create those for you. The full error message includes a link that opens the Firebase console with the index filled in: create it, then wait for it to build (a few minutes at least, longer on big collections). Then add it to firestore.indexes.json and deploy it, so every project has it.
The usual causes, and the fix
01
A query on more than one field
Firestore builds an index for each single field automatically, which covers simple queries. Combine a filter on one field with a sort or range on another, and it needs a composite index on both fields.
// needs a composite index on (ownerId, createdAt) query(collection(db, 'orders'), where('ownerId', '==', user.uid), orderBy('createdAt', 'desc'));02
You can’t see the link
The link to create the index is part of the error message. If your app catches the error and shows something generic, log the full error object, or run the query once in development with the console open. Copy the whole link, including everything after create_composite=.
03
The index is still building
Building an index takes a few minutes even for an empty database, and longer the more documents it covers. Until it finishes, the query keeps failing. The Indexes tab in the Firebase console shows the status.
04
It exists in one project but not the other
Indexes belong to a project. One created by clicking the link in your development project doesn’t exist in production. Keep every index in firestore.indexes.json and deploy it with the Firebase CLI; if you add one in the console, copy it into the file too. firebase firestore:indexes prints the project’s indexes so you can compare.
firebase deploy --only firestore
Checked against the vendor’s docs on : Firebase docs: Manage indexes in Cloud Firestore; Firebase docs: Index types in Cloud Firestore.
Rather hand it over?
Fixed scope, fixed price, paid upfront. The work happens in writing; no call needed.
- from $450App Fix TicketOne reproducible bug in an existing mobile or web app, diagnosed and fixed.See scope and start
- from $450AI-Built App RescueA Lovable, Bolt or Cursor app checked end to end in 3 days, then its worst problems fixed at a fixed price.No issues worth fixing, no charge. If the Launch Check finds nothing rated medium or higher, Simon refunds the full $450. You keep the report either way.See scope and start
Related: Firebase “Missing or insufficient permissions” · How to cut your Firebase bill