Have a graph like below, need to find all the paths count from each A to connected C.
How to achieve this?
Expecting below results for the above graph:
A,C,2 (first A,C)
A,C,3 (second A,C)
Have a graph like below, need to find all the paths count from each A to connected C.
How to achieve this?
Expecting below results for the above graph:
A,C,2 (first A,C)
A,C,3 (second A,C)
Assuming these have a common label (I'll use :Node), this should be easy enough:
MATCH path = (start:Node {name:'A'})-[:CONNECTED*]->(end:Node {name:'C'})
RETURN count(path) as paths
Thank you @andrew_bowman , this will return the overall count.
In my case I have 2 As and 2Cs (They will be connected via some other nodes and relationships, just for the simplicity I have shown as disconnected).
I need to know path count for first A to first C as 2 and second A to second C as 3.
How can I do that?
If you include the variables of the start and end nodes along with the count(), then it should aggregate only between the specific nodes:
MATCH path = (start:Node {name:'A'})-[:CONNECTED*]->(end:Node {name:'C'})
RETURN start, end, count(path) as paths
Thank you @andrew_bowman ! One more query on similar lines, I have a relationship property called health for each, while finding the path between each A and C, I also need to find the overall health.
In the same graph, the relationship between A and B1 is having health "BAD". Expecting below results, how to do this?
First A & C
Path count: 2
Path1: BAD (from A-B1-C)
Path2: Good(from A-B-C)
Second A & C
Path count: 3
Path1: BAD (from A-B1-C)
Path2: GOOD(from A-B-C)
Path3: GOOD(from A-B-B2-C)