1
votes

Do you know how to write a cypher query that would return all the transitive relationships related to a node.

For instance if I have : (node1)-[rel1]->(node2)-[rel2]->(node3).

I'd like a query that, given node1 returns rel1 and rel2.

Thanks for your help !

1

1 Answers

5
votes

You need to use a variable path match, assuming your start node is node 1 having label Label and name='node1':

MATCH path=(node1:Label {name:'node1'})-[*..100]->()
RETURN relationships(path) as rels

The relationships function returns a list holding all relationships along that path. It is a best practice to provide an upper limit to variable depth matches, here I've set it arbitrarily to 100.

update regarding comment below

To get the id's of the relationships:

MATCH path=(node1:Label {name:'node1'})-[*..100]->()
RETURN [r in relationships(path) | ID(x)] as relIds