Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
01-30-2020 07:55 AM
Hi everyone, I'm new to Neo4j but currently what I'm trying to do is visualize a node and all the relationships to it by layers. So for example if we use the movies/actors relationships database that's one of the Neo4j tutorials and I look at tom hanks.
the command of " Match ((n:Person)-[:ACTED_IN]-(b:Movie)) where n.name =~ "Tom Hanks" return n,b"
gives me back Tom Hanks and all of his immediate relationships (all his movies). Now if I want to see what the next layer of relationships-- so all the people connected to those movies how could i do that?
01-30-2020 01:04 PM
Hi
There are 3 relationships until the next (:Movie)
(n:Person)-[1]-(:Movie)-[2]-(:Person)-[3]-(b:Movie)
MATCH (n:Person)-[:ACTED_IN*3]-(b:Movie)
WHERE n.name =~ "Tom Hanks"
RETURN n,b
You can except that the relationship does not come directly.
AND NOT (n)-[:ACTED_IN]-(b)
MATCH (n:Person)-[:ACTED_IN*3]-(b:Movie)
WHERE n.name =~ "Tom Hanks"
AND NOT (n)-[:ACTED_IN]-(b)
RETURN n,b
Or With Person
MATCH (n:Person)-[:ACTED_IN*2]-(n2:Person)-[:ACTED_IN]-(b:Movie)
WHERE n.name =~ "Tom Hanks"
RETURN n2,b
This page will be helpful.
https://neo4j.com/docs/cypher-manual/current/syntax/patterns/#cypher-pattern-varlength
All the sessions of the conference are now available online