Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
11-28-2021 04:00 PM
Hello,
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).
Solved! Go to Solution.
11-30-2021 04:58 PM
If you're only looking at nodes and relationships with the structure of
(User)->[IS_MEMBER_OF]->(Role)->[HAS]->(AccessRight)
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)
11-28-2021 11:51 PM
Hi,
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
11-30-2021 03:15 PM
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:
(User)->[IS_MEMBER_OF]->(Role)->[HAS]->(AccessRight)
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?
11-30-2021 04:58 PM
If you're only looking at nodes and relationships with the structure of
(User)->[IS_MEMBER_OF]->(Role)->[HAS]->(AccessRight)
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)
12-01-2021 08:15 AM
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.
(u:User)-[*]->(ar:AccessRight)
All the sessions of the conference are now available online