Join 2 documents via KEYS that are nested in a third document

This query should get you what you want:

select * from test2 as a join test2 as b on keys [a.friend_id_2] join test2 as c on keys [a.friend_id_1]