how do i fetch all the paths from root to leaf in neo4j and return the result containing nodes and relationships?

A list of all available paths could be obtained as follows.

MATCH p=(root {id: 'start'})-[*]->(leaf)  
// limit the match to the ones that end at a leaf
WHERE NOT (leaf)-->()


RETURN DISTINCT REDUCE (s='', r in RELATIONSHIPS(p) | 
               s+
               CASE WHEN s='' THEN '('+startNode(r).name + ')-[:'+ type(r)+']->('+ endNode(r).name+')'
                    ELSE '-[:'+ type(r)+']->('+ endNode(r).name+')'
               END
       ) AS path

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top