Very slow performance on ANSI JOIN from different bucket

You are Joining Millions of documents and producing more than quarter million documents. It takes time. you can enable Profiling and checkout where it taking time.
If you use EE you can try with HASH JOIN https://blog.couchbase.com/ansi-join-support-n1ql/