Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Create index" link not provided (firebase 8.7.1) #5152

Closed
charles-allen opened this issue Jul 15, 2021 · 44 comments
Closed

"Create index" link not provided (firebase 8.7.1) #5152

charles-allen opened this issue Jul 15, 2021 · 44 comments

Comments

@charles-allen
Copy link

Describe your environment

  • Operating System version: MacOS 11.4 (20F71)
  • Browser version: Node v14.16.0
  • Firebase SDK version: firebase 8.7.1
  • Firebase Product: Firestore

Describe the problem

I wrote a query that requires an index. It errors with this message (which doesn't contain a link to create the index):

  • Expected: link to create index
  • Actual: no link

Screen Shot 2021-07-15 at 13 03 57

Steps to reproduce:

  • Write a query with where/orderBy on multiple fields

Relevant Code:

const query = db.collection('iterations')
  .where('courseCode', '==', code)
  .orderBy('iterationCode', 'desc')
  .limit(1)
  .get()
@google-oss-bot
Copy link
Contributor

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

@DharmarajX24
Copy link

DharmarajX24 commented Jul 15, 2021

It seems that only the Client SDKs are returning an error "FirebaseError: No matching index found" instead of index creation links. The Admin SDK still throws an error with the link. You can try running your query in Firebase Functions emulator and get the link from there. I've posted a similar answer on Stackoverflow.

export const getIndexLink = functions.https.onRequest(async (request, response) => {
    try {
        const snap = const query = db.collection('iterations')
            .where('courseCode', '==', code)
            .orderBy('iterationCode', 'desc')
            .limit(1)
            .get()
        console.log(snap.size)
        response.send( snap.size, "documents matched");
    } catch (error) {
        console.log(error)
        response.send(error.message)
        // Error with index creation link
    }
});

You can try calling this function in a browser and get the index creation link.

@looptheloop88
Copy link

Hi @charles-allen, thanks for the report. I was able to replicate the issue. Let me bring this matter to the attention of our engineers here and update this thread if I have any information to share.

@dreamerchandra
Copy link

I guess the even older versions of firebase library aren't providing url
image

@looptheloop88
Copy link

We're also seeing similar reports on other platforms. It seems to be a backend issue and currently being tracked internally. For reference, see b/193768583.

@jbistis
Copy link

jbistis commented Jul 16, 2021

We are encountering this too for all required indexes not built.
"firebase": "^8.7.1",
"firebase-admin": "^9.11.0",
"firebase-tools": "^9.16.0",

@madisonatamea
Copy link

any updates?

@jaimejangg
Copy link

Got the same error, any updates ?

@jailsondamasceno
Copy link

Looks like we're going to stick with this problem and create the indexes manually :(

@lxieyang
Copy link

Any updates? It breaks my app completely.

@charles-allen
Copy link
Author

charles-allen commented Jul 19, 2021

Any updates? It breaks my app completely.

Unless your app is automatically creating missing indexes (which sounds like a questionable design decision), this is not breaking your app.

Just create the index manually in Firebase Console. It's slightly less convenient, but I wouldn't consider this bug to be blocking.

@r-ndom-developer
Copy link

I'm having the same issue and for some reason I can't even create an index manually from the console.

@DharmarajX24
Copy link

Looks like we're going to stick with this problem and create the indexes manually :(

I mean you can still create those click to create index links from Admin SDK in emulator @jailsondamasceno 👀

@Lazy-Developer-here
Copy link

Hi ,

Any update on this.

FYI If manually create on console it also not working as intended.

@charles-allen
Copy link
Author

charles-allen commented Jul 19, 2021

for some reason I can't even create an index manually from the console.

FYI If manually create on console it also not working as intended.

This is not what I'm seeing. I made an index manually using the console and my code now runs fine.

If you're having problems with the console you should open an issue with details, screenshots, etc.

@dionkas
Copy link

dionkas commented Jul 19, 2021

Also having troubles with this. I can create an index via the console but it still does not recognise it once it is built, giving me the same error.

@jailsondamasceno
Copy link

jailsondamasceno commented Jul 19, 2021

@dionkas Here, likewise

@BluebambooSRL
Copy link

Same problem...

@DualPeaks
Copy link

Same issue and its really costing me a lot of time .... Please fix

@charles-allen
Copy link
Author

charles-allen commented Jul 19, 2021

@r-ndom-developer @Lazy-Developer-here @dionkas @jailsondamasceno - I have only reported the lack of link in the error message. You are not reporting the same as what I'm seeing and reported. If you have an additional issue you must provide:

  • query you're executing
  • index you made (screenshot)
  • error message

In my case, I was able to make an index & run my code. I am not blocked at all. Additionally this was for a class. My students were also able to make the index successfully (though many of them first made typos in the collection name, field names, or direction). In all cases we corrected the index and the code ran successfully.

Please share the details of your failing index

@dionkas
Copy link

dionkas commented Jul 20, 2021

@charles-allen we are reporting the same issue. Not creating indexes via firebase’s “create link” because that is not provided now.
Also, failure to have working indexes when creating via the console is a side effect of this bug you have described. Threads on github are there to discuss what people have tried and what worked or didn’t work to ultimately fix a problem.

@charles-allen
Copy link
Author

charles-allen commented Jul 20, 2021

we are reporting the same issue
...
Also, failure to have working indexes when creating via the console is a side effect of this bug you have described

I'm trying to get you to elaborate on the "also". I don't think broken indexes are a side-effect of the bug I reported. I have repeatedly reported that my indexes are working (when created manually in Firebase Console).

If you have an "also" issue, show it here (or make a new issue).
I suspect that your indexes are broken because you created them incorrectly.

Show what you tried. I don't think you're blocked. I don't think your broken index is related. We can fix it now.

@Lazy-Developer-here
Copy link

Hi @charles-allen ,

Does firestore indexing working for you? able to retrive data for multiple conditions in single query.

For Single query it is working if you add multiple conditions with already created document working?

@charles-allen
Copy link
Author

charles-allen commented Jul 20, 2021

@Lazy-Developer-here

Does firestore indexing working for you?

Yes

able to retrive data for multiple conditions in single query.

Yes, for the query in my original post
Edit: well it's 1 where + 1 order

with already created document working?

Yes, all my documents existed before I made the index

For reference, here is my index:

Screenshot_20210720_163901

Screenshot_20210720_164008

My only issue is that I had to create this index manually. I usually click the link in the error.

This is why I'm encouraging others to share if they are seeing different. Perhaps my example is insufficient; perhaps you can workaround the majority of the pain.

@charles-allen
Copy link
Author

Note: I only replicated this once. From memory my code errored, then I only added the index (and nothing else), and then it worked.

But my memory isn't perfect! Maybe I've missed something or perhaps my example is unusual.

@macmatrix
Copy link

macmatrix commented Jul 20, 2021

Same problem here. I do not get the link from the console and I keep getting the error after creating the index manually.

this is my query

_firestore
          .collection('photos')
          .where('seen', isEqualTo: '')
          .where('uid', isNotEqualTo: appData.user.uid)
          .where('interest', isEqualTo: appData.userInterest)
          .limit(1)
          .get()
          .then((QuerySnapshot snapshot) async {

        if (snapshot.docs.isNotEmpty) {//

and this is my index

Screenshot 2021-07-20 at 10 48 54

Note: indexes like this created previously work fine. The problem is only with new indexes

What am I doing wrong?

@charles-allen
Copy link
Author

charles-allen commented Jul 20, 2021

this is my query

_firestore
          .collection('photos')
          .where('seen', isEqualTo: '')
          .where('uid', isNotEqualTo: appData.user.uid)
          .where('interest', isEqualTo: appData.userInterest)
          .limit(1)
          .get()
          .then((QuerySnapshot snapshot) async {

        if (snapshot.docs.isNotEmpty) {//

I can't see anything obvious (though I confess to not being an index pro!). I guess seen, uid, and interest are all string fields? interest isn't an array?

@macmatrix
Copy link

I can't see anything obvious (though I confess to not being an index pro!). I guess seen, uid, and interest are all string fields? interest isn't an array?

They are all string. Note the uid has a "isNotEqualTo" operator

@charles-allen
Copy link
Author

charles-allen commented Jul 20, 2021

Note the uid has a "isNotEqualTo" operator

Looks valid to me (but again, I'm no expert).

I think the orderBy in my example might be significant. I think the where part and orderBy part use the index in a different way. I read on SO that fields being used to order must be last in the index (no such limitations on the ordering of where fields in your index).

I also read that you can split indexes. I don't know the rules... but perhaps you could try 2 indexes: seen+uid, uid+interest.

One last observation... I can see you have another index on photos specifying userId rather than uid. Is it possible you just got your field name wrong (in both the query & index)?

@macmatrix
Copy link

Nope the names are correct. I am hopeless

@silicakes
Copy link

Happens on v8.3.1 as well.

@schmidt-sebastian
Copy link
Contributor

The problem has been fixed via an update to the backend.

@macmatrix
Copy link

The problem still persists in my app...

I keep getting this error

[VERBOSE-2:ui_dart_state.cc(199)] Unhandled Exception: [cloud_firestore/failed-precondition] Operation was rejected because the system is not in a state required for the operation's execution. If performing a query, ensure it has been indexed via the Firebase console.

@marlow-fawn
Copy link

The problem has been fixed via an update to the backend.

When will this fix be available?

@AliciaAMT
Copy link

It is fixed already, but you may have to update Chrome and restart it. I had this problem yesterday, but after Chrome update and restart it works!

@sajitkhadka
Copy link

Still giving me the error! Not sure why the issue has been closed.
image

@silicakes
Copy link

The problem has been fixed via an update to the backend.

@schmidt-sebastian Still seeing it as well.

@miszmaniac
Copy link

The problem has been fixed via an update to the backend.

@schmidt-sebastian Still seeing it as well.

same here

@jailsondamasceno
Copy link

jailsondamasceno commented Jul 20, 2021

here too.
It's totally broken.
In my case it breaks when placing the order by.
And if I don't put the order by, the error doesn't happen, which is also an error because I put a combination of 4 "where" and even though I didn't create an index, the error didn't appear, it made the call.

@jailsondamasceno
Copy link

Hi guys, I did the cli deployment using the json file, and it worked.
image


@schmidt-sebastian
Copy link
Contributor

I am confirming with the backend team to see when this issue should be fully mitigated. This is a server-side only issue and should not require any changes on your end.

@charles-allen
Copy link
Author

charles-allen commented Jul 20, 2021

In my case it breaks when placing the order by.
And if I don't put the order by, the error doesn't happen, which is also an error because I put a combination of 4 "where" and even though I didn't create an index, the error didn't appear, it made the call.

I think this is actually normal (the 2nd part), albeit unexpected behavior. I guess all your where clauses are just equals. I think the indexes are only needed when you have inequalities (>, >=, etc), not-equals, not-in, ordering.

Multiple equals conditions seems to work by default (did for my query with 2 equals only), I guess by combining the default single indexes??

@charles-allen
Copy link
Author

charles-allen commented Jul 21, 2021

The problem has been fixed via an update to the backend.

Thanks for the updates @schmidt-sebastian

schmidt-sebastian closed this

Suggest you update your DoD to include "fix fully deployed" to block closing public issues before the fix is available to everyone (it causes confusion closing it early; and none of us care about the issue's status on Github, only whether the fix is working).

Edit: this was supposed to be a helpful suggestion, but when I read it back, it sounds bad. Sorry!

@silicakes
Copy link

Confirmed working.

@firebase firebase locked and limited conversation to collaborators Aug 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests