Considering a collection in Cloud Firestore on which we do the following three queries:
1
c.where('a', '==', 'value1')
.where('b', '==', 'value2')
.where('c', '>=', 1)
.orderBy('c', 'desc')
2
c.where('a', '==', 'value1')
.where('c', '>=', 1)
.orderBy('c', 'desc')
3
c.where('b', '==', 'value2')
.where('c', '>=', 1)
.orderBy('c', 'desc')
That is we order on field c
, and filter on either or both of a
and b
.
Firestore tells me I need 3 separate indexes, one index for each of those queries, i.e.
a ASCENDING, b ASCENDING, c DESCENDING
a ASCENDING, c DESCENDING
b ASCENDING, c DESCENDING
Is there a way I can structure these queries or indexes so that Firestore can commonise or merge some or all of the indexes?
This is a specific illustration for clarity, but it would help anyone to understand how Firestore can and cannot combine indices.
I have all single-field indexes disabled on the collection. The key motivation is to optimise index storage size (money) on large collections (and perhaps performance).