Mohammad Shraim
Mohammad Shraim

Reputation: 1303

Firestore index limitation for document

According to Firestore documentation about index limitations:

Maximum sum of the following for a document: 20,000

  • The number of single-field index entries

  • The number of composite index entries

I can't understand what is that means. Is it:

Upvotes: 2

Views: 5512

Answers (2)

Juan Lara
Juan Lara

Reputation: 6854

Update: The limit is now 40,000 index entries per document.

This limit affects the maximum number of fields you can index for each document. For example, Cloud Firestore automatically creates an ascending single-field index entry and a descending single-field index entry for each string field. A document with only string fields and no composite indexes, could have a maximum of 20,000 fields.

We updated the docs to clarify: https://firebase.google.com/docs/firestore/query-data/index-overview#index_limitations

Upvotes: 6

Philip
Philip

Reputation: 136

Note that firestore also adds indexes for arrays so this limit will be lower if you are using arrays. Since the two indexes firestore creates are ascending and descending, then you can manually delete these if you do not need them for a specific query (e.g. only need descending index) or delete them completely if you don't want to query a specific field (or you don't want the performance hit of firestore indexing a big random data field).

It is recommended to do this if the data is large (I do it on storage of data which is a book chapter and therefore will never be searched in my application).

Indexes can be removed by going to the firebase console firestore view and clicking on indexes followed by Simple indexes and then clicking on the Add Exemption button.

You can remove an ascending, descending or array index.

So if you are hitting the 20,000 limits you can delay hitting it by removing all the unused indexes.

There is no way to use a tool such as firebase cli tools to remove indexes (unfortunately).

The link below "Correct Answer - green tick" talks about the index removal and limitations with screenshots.

How to delete Single-field indexes that generated automatically by firestore?

Upvotes: 2

Related Questions