Save the (A)->...->(Z)
subgraph to a named path then use the nodes
and relationships
functions to extract a list of nodes and relationships:
MATCH p=(a {Id: '123'})-[:flows*]->(z {Id: '456'})
RETURN a, nodes(p), relationships(p), z
As pointed out in the comments, nodes(p)
also returns a
and z
. If you do not want those nodes to be returned, omit the first and last elements of the list. Thanks to Bruno Peres and cybersam for their inputs.
MATCH p=(a {Id: '123'})-[:flows*]->(z {Id: '456'})
RETURN a, nodes(p)[1..-1], relationships(p), z
Remark #1. It is also possible to UNWIND
these lists to their content process one-by-one.
Remark #2. Depending on the driver your using, you can simply return p
and process it in the client's code. For example, the Java driver allows use to return a Path
object that has nodes()
and relationships()
methods returning Iterable
s.