Index query not returning results


I’m running this query:

        Ref(Collection('users'), "307731780020994112")

On this index:

  name: "chatMemberships_by_user",
  serialized: true,
  source: "chats",
  terms: [
      field: ["data", "user"]
  values: [
      field: ["data", "lastActive"]
      field: ["data", "chat"]
      field: ["ref"]

The chatMemberships collection contains these two documents:

After running the query, the result I get is an empty array instead of an array containing the matching chatMembership document (should be the first one in the screenshot).

{ data: [] }

Any idea on what’s causing this? Am I crazy or is this a bug? Thanks!

Hi @Michael_Tromba and welcome to the forums!

Did you create the data shortly after creating the index? There can be a delay between creating an index and data being written to it.

Can you check out this previous topic and see if it applies to you? Instance not found even though instance exists and unique rule being ignored

Hi Paul, thanks for your comment. I believe the data was created prior to creating the index. I just ran the query again, and still no results. If there was a delay, surely it would have been synced by now? (4h later)

I can try re-writing the documents to the collection, but if that fixes it, I would be quite worried about this occurring in production in the future whenever new indexes are created…

There is no need to delete the documents and recreate them. But you should be able to delete and recreate the index to fix your issue.

FQL relies on the names as ID’s. This means that you can even create a new index and then swap the names to limit downtime if necessary.

The big thing here to watch out for is the delay in writing a new index. As I said in the previous post, there can be a delay between creating an Index (and active is set to true ) and the index being recognized to be written. We have an update ready for release that will ensure that there is never such a delay.

But for now, you can do the following:

  • Delete the offending Index
  • Recreate the Index
  • Wait at least 5 minutes to add any Documents to the source Collection(s).

Please the linked topic for details of upcoming improvements.

In addition to that, you can look at the dashboard > indexes, you will see the list of all your indexes, just click on the new one you created, if you see a message that says “your index is being created” (or similar) then it’s not ready to be used yet, you’ll have to wait until that’s over.

1 Like

Thank you both very much for your generous help. Someone on stack overflow just pointed out to me that I’m referencing the wrong source collection in the index: it should be “chatMemberships” instead of “chats”. All just a dumb mistake on my part! Sorry about that, and thanks again.

1 Like

This topic was automatically closed after 47 hours. New replies are no longer allowed.