firestore.indexes.json generator

Generate the exact composite index a Firestore query needs—from a query builder or a missing-index error link—then validate and merge it into your firestore.indexes.json.

Runs locally in your browser. Nothing you enter leaves this page.

Last reviewed:

1. Describe the index

Query

The last segment of the path: orders for users/{uid}/orders. Collection group queries every collection with that ID.

where()

orderBy()

Field paths as in the SDK, such as address.city. Use __name__ for the document ID (documentId()).

Needs a composite index.

Needs a composite index

Combining an equality filter with a sort order or a range filter on another field needs a composite index.

  1. Equality filters (== and in) come first: country.
  2. Then the orderBy clauses, in the order written: population desc.
  3. Firestore adds __name__ (the document ID) in the direction of the last field (descending), so the file can leave it out.

indexes entry

{
  "collectionGroup": "cities",
  "queryScope": "COLLECTION",
  "fields": [
    {
      "fieldPath": "country",
      "order": "ASCENDING"
    },
    {
      "fieldPath": "population",
      "order": "DESCENDING"
    }
  ]
}

The query (JavaScript SDK)

import { collection, getDocs, orderBy, query, where } from "firebase/firestore";

const q = query(
  collection(db, "cities"),
  where("country", "==", "value"),
  orderBy("population", "desc"),
);
const snapshot = await getDocs(q);

Replace the placeholder values with yours: the values do not change the index.

2. Add it to your file (optional)

Paste your current firestore.indexes.json, or the output of firebase firestore:indexes. It is checked, and the new entry is added unless the file already has the same index. In Field override mode, the entry replaces the file's override for the same field.

3. Your firestore.indexes.json

A new file with this entry. Paste your current file in step 2 to merge it instead.

{
  "indexes": [
    {
      "collectionGroup": "cities",
      "queryScope": "COLLECTION",
      "fields": [
        {
          "fieldPath": "country",
          "order": "ASCENDING"
        },
        {
          "fieldPath": "population",
          "order": "DESCENDING"
        }
      ]
    }
  ],
  "fieldOverrides": []
}

Deploy it

firebase deploy --only firestore:indexes

It deploys the indexes file of every database listed in firebase.json, and no security rules. For each database, indexes missing from its file are deleted after a prompt (or at once with --force).

Start from firebase firestore:indexes so the file lists the indexes you already have.

Three ways in, one file out

From a query

Define your collection, filters, orderBy clauses, and optional vector search. The tool applies Firestore's indexing rules to generate the required entry, explain when no composite index is needed, or flag query limitations Firestore would reject.

From an error link

Paste a The query requires an index error message—or just the URL. Its create_composite or create_exemption parameter encodes the index definition as a protobuf payload, which the tool decodes into JSON locally without opening the link.

Into your file

Paste your existing firestore.indexes.json to check it for syntax errors (with line and column), unknown keys, invalid values, and duplicates. The new entry is merged in automatically unless an equivalent index is already present; in Field override mode, it replaces any existing override for the same field.

When Firestore needs a composite index

Automatic indexes cover single fields

Firestore automatically maintains ascending, descending, and array-contains single-field indexes with collection scope (index overview). Single-field queries like where("state", "==", "CA") or orderBy("name") work out of the box.

Equalities can merge

Multiple == or in filters without sorting are served by merging single-field indexes (index overview). When combining array-contains with an equality filter, Firebase recommends a composite index to avoid merge overhead.

Equality plus a range or sort

Combining an equality filter with <, <=, >, >=, or != on another field—or with an orderBy on another field—requires a composite index (queries). For example, where("country", "==", "USA").orderBy("population", "desc") needs country ascending followed by population descending.

Field order matters

Equality fields come first, followed by Firestore's sort order: your orderBy clauses, then any remaining inequality fields sorted lexicographically by field name (uppercase before lowercase) in the direction of the last orderBy (query.proto). So where("a", ">", 1).orderBy("b") requires b then a, and two range filters without orderBy appear in lexicographic ascending order.

Collection groups

Collection group queries that filter or sort require collection-group-scoped indexes, which Firestore does not create automatically (index overview). A single field needs a fieldOverrides entry; multiple fields require a composite index with "queryScope": "COLLECTION_GROUP".

Vector search

findNearest requires a vector index matching your embeddings' dimension (up to 2,048). When combined with prefilters, the filtered fields and the vector field belong in one composite index (vector search). Note that vector search runs only in server client libraries, not the web SDK.

The firestore.indexes.json format

  • indexes: Composite index definitions, each with a collectionGroup (collection ID), queryScope (COLLECTION or COLLECTION_GROUP), and fields array.
  • fields: Each item pairs a fieldPath with exactly one of order (ASCENDING or DESCENDING), arrayConfig (CONTAINS), or vectorConfig ({"dimension": 768, "flat": {}}).
  • __name__: The document ID. Firestore appends it automatically in the direction of the last sorted field (index overview); include it explicitly only when sorting document IDs in the opposite direction.
  • apiScope, density, multikey: Optional keys. Standard edition databases only accept ANY_API and SPARSE_ALL (and ignore multikey); Enterprise edition uses them for MongoDB compatibility and dense indexes.
  • fieldOverrides: Single-field index settings, one entry per collectionGroup and fieldPath. Its indexes list controls which single-field indexes to keep—an empty list disables indexing for that field—and "ttl": true configures a TTL policy.

See Firebase's index definition reference for the full schema. The Firebase CLI rejects a unique key on composite indexes as well as string ttl values (firebase-tools index validation), and parses the file with comments allowed.

{
  "indexes": [
    {
      "collectionGroup": "orders",
      "queryScope": "COLLECTION",
      "fields": [
        { "fieldPath": "status", "order": "ASCENDING" },
        { "fieldPath": "createdAt", "order": "DESCENDING" }
      ]
    }
  ],
  "fieldOverrides": [
    {
      "collectionGroup": "sessions",
      "fieldPath": "expiresAt",
      "ttl": true,
      "indexes": [
        { "order": "ASCENDING", "queryScope": "COLLECTION" },
        { "order": "DESCENDING", "queryScope": "COLLECTION" },
        { "arrayConfig": "CONTAINS", "queryScope": "COLLECTION" }
      ]
    }
  ]
}

Deploy with firebase deploy --only firestore:indexes to push indexes for every database configured in firebase.json without touching security rules. --only firestore deploys both rules and indexes for every database (Firebase CLI reference), while --only firestore:<database> targets a single database along with its rules—the CLI has no target for deploying one database's indexes alone (firebase-tools deploy targets).

Run firebase firestore:indexes to export your currently deployed indexes (index definition reference) in this format, including explicit __name__ entries (firebase-tools indexes list command).

Deploying removes any index absent from the file (after a confirmation prompt, or immediately with --force), so keep every index your app still uses in the file.

Firestore index limits and tool boundaries

Firestore index limits

  • Composite indexes: 200 per database on the free tier, 1,000 with billing enabled (quotas).
  • Single-field configurations: Same limits (200 free, 1,000 billed). An exemption and a TTL policy on the same field count as one.
  • Fields per index: Up to 100, with at most one array field per index.
  • Index entries per document: Up to 40,000 entries, each at most 7.5 KiB and 8 MiB total.
  • Indexed values: Field values larger than 1,500 bytes are truncated in the index.
  • Range fields: Range or inequality filters can span at most 10 fields per query (multiple range fields).
  • Vector dimension: Up to 2,048 dimensions (vector search).

What this tool doesn't check

  • OR queries: Firestore evaluates each branch using its own index, whereas this tool derives indexes for AND queries only.
  • Indexes already deployed to your database: the tool only inspects the file you paste.
  • Range-field selectivity: when filtering on multiple range fields, place the most selective field first in orderBy as recommended by Firebase.
  • Enterprise-only indexes, search indexes, and filter value limits (such as 30 values for in and 10 for not-in).
  • Whether a field override replaces automatic indexes: following Firebase CLI deploy behavior, the tool assumes it does and lists the kept indexes explicitly.

Frequently asked questions

Why does my Firestore query need a composite index?

Firestore only creates automatic indexes for single fields. Any query that combines an equality filter with a range filter or sort on another field, sorts by multiple fields, or filters a collection group requires a composite index containing those fields in the exact order the query reads them.

Can I extract the index from an error link without opening the Firebase console?

Yes. The create_composite parameter in the error URL is the base64-encoded index definition. Paste either the full error message or the URL into the generator to decode it into a firestore.indexes.json entry that you can deploy with the Firebase CLI.

What order should fields appear in a composite index?

Put equality fields first, followed by your orderBy clauses, then any remaining inequality fields sorted lexicographically by field name (uppercase before lowercase) in the direction of the last orderBy. The document ID (__name__) always comes last.

How do I deploy firestore.indexes.json?

Point firestore.indexes in firebase.json to your file and run firebase deploy --only firestore:indexes. This deploys indexes for every database configured in firebase.json without touching security rules. Because deploying removes any index missing from the file (after a confirmation prompt), start by running firebase firestore:indexes to export your existing indexes first.

Are my queries or index files sent to a server?

No. Everything runs locally in your browser—your queries, decoded error links, and pasted files never leave the page.

Related guides

Indexes in Fuego

  • The Index Advisor checks your query against the composite indexes and single-field exemptions already deployed to your database, and can verify its advice with Query Explain.
  • Click Copy definition to copy an index as a firestore.indexes.json entry, or Export report to generate a ready-to-deploy firestore.indexes.json file.
  • Index management lets you list, create, and delete composite and vector indexes, manage single-field exemptions and TTL policies, and compare indexes across two databases.

Manage indexes on your live database

Fuego is a desktop Firestore client for macOS, Windows, and Linux. Its Index Advisor checks your queries directly against the indexes already deployed to your database.