Thomas
Thomas

Reputation: 182000

How to create an index exemption on Firestore subdocuments?

We have a database structured as follows:

Trying to write a document to the bar collection containing 34571 fields, I get (from the Go API):

rpc error: code = InvalidArgument desc = too many builtin index entries for entity

OK, fine, it seems I need to add an exemption:

Large array or map fields

Large array or map fields can approach the limit of 20,000 index entries per document. If you are not querying based on a large array or map field, you should exempt it from indexing.

But how? The console only lets me set a single collection name and a single field path, and slashes aren't accepted:

"Add exemption" dialog

I tried other combinations, but / isn't accepted in either the Collection ID or the Field path, and using ., while not clearly forbidden, results in a generic error when trying to save the exemption. I'm also not sure if * is allowed.

Upvotes: 10

Views: 2971

Answers (1)

Juan Lara
Juan Lara

Reputation: 6854

Update: You can now use the * wildcard to add collection-level index exemptions on all fields in a collection group

Previous: Index exemptions are based on collection ID and not collection path. In this case, you can enter bar as the collection ID. This also means the exemption applies to all collections with ID bar, regardless of hierarchy.

As for the fields, you can specify only a single field path per exemption. The "*" all-selector is not supported. There is a limit of 200 index exemptions so you wouldn't be able to exempt all 34571 fields. If possible, I suggest moving your fields into a map. Then you could disable indexing on the map field.

Upvotes: 13

Related Questions