cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Getting relationships from variable length path

MATCH p=(user)-[r1:roles]->(role1:`Role`)-[:include*0..]->(role2:`Role`)

I need to get only relationships with type include from the cypher above. Thanks.

1 ACCEPTED SOLUTION

You can use relationships(p) to get the list of relationships in the path, and you can combine that with a filter to only get the ones that are of type include:

MATCH p=(user)-[r1:roles]->(role1:`Role`)-[:include*0..]->(role2:`Role`)
WITH [rel in relationships(p) WHERE type(rel) = 'include'] as includeRels
...

View solution in original post

2 REPLIES 2

You can use relationships(p) to get the list of relationships in the path, and you can combine that with a filter to only get the ones that are of type include:

MATCH p=(user)-[r1:roles]->(role1:`Role`)-[:include*0..]->(role2:`Role`)
WITH [rel in relationships(p) WHERE type(rel) = 'include'] as includeRels
...