Cypher Query to return all nodes and relationships under a tree

3,523 views
Skip to first unread message

Christopher Hydak

unread,
Dec 23, 2013, 1:40:40 PM12/23/13
to ne...@googlegroups.com
My graph is constructed with separate trees, which indicate customers.  Almost all nodes and relationships under that customer should not connect to anything outside of the tree.  Other than recursively calling neo4j for each node in the tree, is there a good cypher query to find the nodes and relationships under the tree starting at the root of the tree?  The depth is unknown at this time, but can be (for now) assumed to be < 15.  There are about 120 relationship types, and these are variable, so we can't explicitly list those.  There are some (like 3 exceptions) that I would like to exclude based upon the relationship name.

Thanks,
Christopher

Wes Freeman

unread,
Dec 23, 2013, 2:15:44 PM12/23/13
to ne...@googlegroups.com
How do you want them to be returned. Is this good enough?

MATCH (root:Customer)-[r*]->(child)
WHERE root.id = {custId}
   AND NOT type(r) IN ["exception1", "exception2", "exception3"]
RETURN *

Wes

--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Christopher Hydak

unread,
Dec 23, 2013, 4:22:27 PM12/23/13
to ne...@googlegroups.com
It doesn't like r*.    Expected `r` to be a Relationship but it was a Collection.  I'm using 1.9.5

Michael Hunger

unread,
Dec 24, 2013, 7:14:20 PM12/24/13
to ne...@googlegroups.com
MATCH (root:Customer)-[rels*]->(child)
WHERE root.id = {custId}
   AND NONE(r in rels : type(r) IN ["exception1", "exception2", "exception3"])
RETURN *

Karol Brejna

unread,
Dec 25, 2013, 2:31:36 AM12/25/13
to ne...@googlegroups.com
   AND NONE(r in rels : type(r) IN ["exception1", "exception2", "exception3"])
I think it should be: and none(r in rels WHERE typer(r) in  ["exception1", "exception2", "exception3"])

Where in place of colon.

Regards,
Karol

Michael Hunger

unread,
Dec 25, 2013, 7:04:02 AM12/25/13
to ne...@googlegroups.com
True that ;) thx

Sent from mobile device
--
Reply all
Reply to author
Forward
0 new messages