Hi,
I have data like the above image, here my task is when I query the Starting node (here "A1", "B1", and "C1" are the the starting nodes for 3 different paths), I need to get all the path of the nodes. Like when I query "A1" I need to get "A1", "A2", "A3", "A4" and so on till "A7".
Problem is we don't know the number of such connections for a path, as you can see from the image "A" label have 7 conncetions whereas "B" has only 5. Second problem is we don't have the same reltionships between the paths, like relationship between "A1" and "A2" can differ between "A2" and "A3".
Hence I used "apoc.path.expand", this solves all the above problem but it doesn't give the relationships between the nodes. As I want the name of the relationship between nodes also the properties of the relationships.
It would be greatful if someone could help me here. Thanks in advance.
You can get the relationships along a path 'p' with 'relationships(p)' For each relationship 'r' in the collection, you can get its properties with 'properties(r)' and its type with 'type(r).'
One approach to extracting this data is to return it as list of maps for each path. A single map has the properties and type for one relationship along the path. As an example, assume this data:
create(:Node{id:0})-[:A{value:10, color:'blue'}]->(:Node{id:1})-[:B{value:20, color:'green'}]->(:Node{id:2})
Then this query extracts the relationship properties and types.
match p=(:Node{id:0})-[*]-(:Node{id:2})
return [x in relationships(p) | x{.*, type: type(x)}] as rels
BTW- if your structures are simply linked list of nodes, then you can use a query similar to the one above instead of apoc.path.expand. In particular, this should give you the same result, assuming you set the conditions for the root node.
match p=(:Node{id:0})-[*]->(m)
where not exists((m)-->())
return [x in relationships(p) | x{.*, type: type(x)}] as rels