About performance using has_child query for filtering

This is a tough problem. I guess you have two options:

  1. use parent/child like you describe

  2. add an interacted_with field to all your documents and update your documents to append to this list whenever there are interactions

  3. will be slow and makes sharding complicated while 2. will become problematic if you start having millions of entries for the interacted_with field.

Maybe it's best to make conscious trade-offs. For instance you could go with option 2 and make the interacted_with field a rolling buffer: whenever it reaches its maximum size (eg. 10000) then instead of just appending to it, you would also remove the first value, which is the 10000th user that the current user interacted with last. It is less correct but help keep the problem bounded and might be good enough for your users.