0
votes

I would like to write a query that only returns the nodes that have more than one path to another node. (only show the redundant paths to any other node / only show subgraphs that are cyclic)

This is an example from using BloodHoundAD which uses a Neo4j db.

This query for example returns all the paths from Users who have a nested 'MemberOf' relationship to groups.

MATCH p=(u:User)-[r:MemberOf*4..8]->(g:Group) RETURN p

How could I query this in a way to only show the redundant paths?

To illustrate this I've attached an image. Here I would like to discard the path circled in blue and only show the redundant paths (circled in red)

Graph with redundant paths circled in red

1

1 Answers

0
votes

Redundant paths means there's more than one path to the same node, so you would collect the paths with respect to the start and end nodes and filter to keep rows where there is more than one path in the list:

MATCH p=(u:User)-[:MemberOf*4..8]->(g:Group) 
WITH u, g, collect(p) as paths
WHERE size(paths) > 1
RETURN u, g, paths