Composite Indexes

329 views
Skip to first unread message

Jethro Bodine

unread,
Jul 15, 2021, 12:48:05 AM7/15/21
to Firebase Google Group
I've had an issue creating a working composite index in Firestore and noticed a post on stackoverflow yesterday expressing the same problem.

The docs seem clear and straightforward enough but when attempting to run this...
checkinQuery = db.collection('places').doc('starbucks').collection('checkins')
checkinQuery.where('pref', 'array-contains', 'male').where('time', '<', Date.now()).get().then(docs=>{console.log(docs[0])})

I get the error (after creating the composite index manually for 'pref' and 'time') ...
"FirebaseError: [code=failed-precondition]: no matching index found."

With no link to automatically create the index either. Am i missing something simple here? or is there something happening on firebase end?

Thanks,
Jeff

Sam Stern

unread,
Jul 15, 2021, 1:08:07 PM7/15/21
to fireba...@googlegroups.com
Hi Jeff,

As you said, you're not the only one experiencing this issue. We're investigating it now, not sure if this is an SDK or backend issue but that error message should definitely have the link.

Would you mind sharing a screenshot of the index in the console that you think should be serving this query? Then I'll be able to tell if there's a backend indexing problem (scary!) or just a problem with error messages (inconvenient, but not scary).

- Sam

--
You received this message because you are subscribed to the Google Groups "Firebase Google Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to firebase-tal...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/firebase-talk/a21f3a50-14bb-4229-bd9c-418b848a260bn%40googlegroups.com.

Jethro Bodine

unread,
Jul 15, 2021, 4:15:50 PM7/15/21
to Firebase Google Group
Sure. this is the second time rebuilding them. I built them first before realizing you could use the link method. When that didn't work, I erased them but the error persisted and still no link.
Screenshot 2021-07-15 151419.png

Sam Stern

unread,
Jul 16, 2021, 5:38:37 AM7/16/21
to fireba...@googlegroups.com
Hi Jeff,

Thanks for the screenshot. It looks like the order of fields in your index does not match the order of clauses in your queries? Try creating a new index which looks like this, I think that will solve your issue:
Screen Shot 2021-07-16 at 10.37.39 AM.png

- Sam

Jethro Bodine

unread,
Jul 16, 2021, 6:13:03 AM7/16/21
to Firebase Google Group
I tried just swapping the query order. that still produced the same error. I'll make a new index but highly doubt that will change anything now. And still doesnt explain why no link is provided. And just completed after building new index - confirmed its still not working. With yet another SO post in the last few hours it seems to be pointing to an SDK or backend problem unfortunately...

Sam Stern

unread,
Jul 16, 2021, 8:40:04 AM7/16/21
to fireba...@googlegroups.com
Hi Jethro,

I agree that is concerning. At this point I think someone would probably need to look into your project specifically in order to debug further. Can you file a ticket with Firebase Support: https://firebase.google.com/support

You can link to this email thread so they can see what questions I have already asked you and hopefully pick up from there.

- Sam

Jethro Bodine

unread,
Jul 16, 2021, 4:37:28 PM7/16/21
to Firebase Google Group
Support ticket was filed.  i'll update here if it gets diagnosed and fixed properly

Thanks for the help Sam 

mrsc...@google.com

unread,
Jul 20, 2021, 12:58:44 PM7/20/21
to Firebase Google Group
The underlying issue should now be fixed. You do not need to update your SDKs as these links are generated by the backend.

Jethro Bodine

unread,
Jul 20, 2021, 2:35:20 PM7/20/21
to Firebase Google Group
Unfortunately still having the same exact error. I deleted the manual index to see if it would work then, but no luck. Then manually rebuilt index again and same result of throwing "Uncaught (in promise) FirebaseError: no matching index found." with no link generated either time. Whats odd is the manual index i built for the time field 'descending' does indeed work. But not the ascending one.

Not sure where to go from here

Jethro Bodine

unread,
Jul 20, 2021, 9:07:44 PM7/20/21
to Firebase Google Group
Happy to report the the link is now being provided and results are being returned as expected. Thanks a bunch!!

Jethro Bodine

unread,
Jul 22, 2021, 1:23:24 AM7/22/21
to Firebase Google Group
Well a new problem related to this seems to have emerged.  

It appears the composite index I made with the link doesn't return any results. I save that exact query however and perform a .get() on it again and it works the second time onward. I'm not sure what the cause of this behavior is or if I'm doing something wrong. Or perhaps its some kind of timing issue. 

I've tried the .get() with both a .then() & async/await methods, and each return an empty result after. But return the expected result if I query it again in the very next line of code.

Please advise on next steps to solve this new issue.
Thanks, Jeff

Reply all
Reply to author
Forward
0 new messages