Cypher querry to detect redundant paths

I am not able to implement a simple query, so I am looking for help here.

How can I get all paths from a graph, where is more than one path from the start node to the end node.
So, I am basically looking for all the duplicities in paths. For example, all possible railway lines from town A to town B, no matter how long they are, how many other cities do we visit. (railway lines are one way in this case).

this is related to variable path length. A query would look somewhat like this:
MATCH paths = (a:Town {name: "Town A"})-[*]->(b:Town {name: "Town B"})
RETURN paths
Also see Patterns - Neo4j Cypher Manual

Thanks for your response.
More specifically, I need to do that on the whole graph with a single query.

I am basically making a risk assessment on an identity management system, which has data stored in the Neo4j database. The simplified schema looks like this:

My task is to implement a query, that will report all pairs (User, AccessRight), that have more than 1 path between them. Do you have any suggestions for that?

If you're only looking at nodes and relationships with the structure of
you can try the following query

MATCH path=(u:User)->[:IS_MEMBER_OF]->(:Role)->[:HAS]->(ar:AccessRight)
WITH u, ar, collect(path) as paths
WHERE size(paths) > 1
RETURN u, ar, size(paths) AS numPaths

kevintim's query would be useful for cases where the node/relationship labels along each path could vary, as opposed to having a consistent schema such as (User)->[IS_MEMBER_OF]->(Role)->[HAS]->(AccessRight)

1 Like

Thank you.
It is working like expected, but I discovered that in the graph are some direct AccessRights from the User. Therefore I did a small change in the first line of the query.

1 Like