In AWS Neptune, I have a graph that has many clusters like the one defined below:
g.addV('person').property('name', 'John').as('p1')
.addV('person').property('name', 'Weihua').as('p2')
.addV('Fellowship of the Ring').as('movie1')
.addV('A New Hope').as('movie2')
.addE('likes_movie').from('p1').to('movie1')
.addE('likes_movie').from('p1').to('movie2')
.addE('likes_movie').from('p2').to('movie1')
.addE('likes_movie').from('p2').to('movie2')
Each cluster contains a number of movie nodes and person nodes with connections indicating which movies people like. How can I write a query that finds every pair of two person nodes that share two liked movies in common and create a "shares_two_liked_movies" relationship between them? Such a query would result in my cluster looking like this:
So far, I've realized that I can detect a person has any other person who shares two liked movies with them if the query
g.V().has('name', 'John').as('src').out('likes_movie').in().where(neq('src'))
returns the same vertex id twice. However, I'm not sure how to translate this into the query I want.