I am trying to simplify the index creation in Cloud Firestore. It keeps asking me to create new indexes for anything I do in my app. For e.g., I have the following table, which shows a list of incidents. Users can filter based on 5 different fields and can apply a combination of those fields while searching. I have created like 20 indexes to support this table. It is very easy to miss some of the combinations in the index, and then that query doesn't work.
I am trying to understand, isn't there a way to like, mention I want to search on these five fields in any combination?
Whenever I add another field to the filtering, it adds up a lot of work and testing, and I doubt whether everything will work as expected once I push to production.
I am trying to simplify the index creation in Cloud Firestore. It keeps asking me to create new indexes for anything I do in my app. For e.g., I have the following table, which shows a list of incidents. Users can filter based on 5 different fields and can apply a combination of those fields while searching. I have created like 20 indexes to support this table. It is very easy to miss some of the combinations in the index, and then that query doesn't work.
I am trying to understand, isn't there a way to like, mention I want to search on these five fields in any combination?
Whenever I add another field to the filtering, it adds up a lot of work and testing, and I doubt whether everything will work as expected once I push to production.
Share Improve this question edited Mar 28 at 7:08 Alex Mamo 139k18 gold badges169 silver badges201 bronze badges Recognized by Google Cloud Collective asked Mar 27 at 6:40 Varun GuptaVarun Gupta 3,1546 gold badges38 silver badges76 bronze badges 01 Answer
Reset to default 2I am trying to understand isn't there a way to like mention I want to search on these five fields in any combination?
No, there is not. You cannot specify some field names and create the corresponding indexes or a combination of indexes automatically. You either perform all those queries, extract from the error message the URL that creates the index automatically for you, or you can use the Firebase CLI to simplify the process.
However, even though it is mandatory to create an index for every query, it is not always necessary to have one index per query. I'm saying that because you can use index merging:
For queries with multiple equality (
==
) clauses and, optionally, anorderBy
clause, Cloud Firestore can re-use existing indexes. Cloud Firestore can merge the indexes for simple equality filters to build the composite indexes needed for larger equality queries.