I'm looking for a performant way of retrieving all connected nodes. However there is a twist. I would like to exclude nodes and consequent children, that are connected via certain relationship types.
The attached figure illustrates my case.
There are two or more clusters of nodes. I would like to retrieve all nodes of a single cluster, depending on the id inside the query. All other nodes (coming from different clusters) and connected via "LINK..." relations shall not be included.
I know how to retrieve all connected nodes via:
MATCH (n:MyNode {id : 123})-[*]-(connectedNodes)
RETURN connectedNodes
Filtering with the WHERE
clause sounds like a bad idea, because it would still fetch the whole graph. Is there maybe something inside the APOC procedures, that would allow me to do something in that manner? Thanks a lot already for your help.
EDIT 1: sofar I tried the first suggestion given in the comments but the execution time was not sufficient. I will try to restrict relationahip and node types afterall. Also I tried a custom implementation inside Python using a recursive function. Not finalized yet though.
EDIT 2: @InverseFalcon's suggestion worked liked a charm. First filter all available relationship types for the once that shall not be considered and then applying the apoc.path.subgraphNodes
procedure with the respective starting node and the valid relationship types. Thank you.