Reputation: 39
How can I find some connection between the Actor node with id=1100 and the Actor node with id=65731 in Neo4j graph Movie database from the neo4j sample dataset? I have tried a lot but so far I know that id 11oo is Arnold Schwarzenegger and id 65731 is Sam Worthington.When I run Cypher using ACTS_In relationship its shows no movie together.
For finding name i have used this Cypher:
MATCH (a:Actor {id:"1100"}),(b:Actor {id:"65731"})
RETURN a.name, b.name
For finding relationship I have used this Cypher:
Match(a:Actor{name:"Arnold Schwarzenegger"})-[:ACTS_IN]->()<-[:ACTS_IN]-(b:Actor{name:"Sam Worthington"})
using index a:Actor(name)
using index b:Actor(name)
return count(*)
I am looking for any kind of connection. Not only the same movie.
Upvotes: 2
Views: 611
Reputation: 67019
In general, to find the paths between any 2 nodes, you can perform a variable-length relationship query.
For example:
MATCH path=(a:Actor{name:"Arnold Schwarzenegger"})-[*]-(b:Actor{name:"Sam Worthington"})
RETURN path;
Note, however, that unbounded variable-length relationship queries can take a very long time to complete (or may seem to never complete), even with relatively small DBs. The best practice is to put a reasonable upper bound on the depth of the query. For example, to search for path depths of at most 5:
MATCH path=(a:Actor{name:"Arnold Schwarzenegger"})-[*..5]-(b:Actor{name:"Sam Worthington"})
RETURN path;
Upvotes: 1