Problems matching a whole subgraph without knowledge about content

Hello dear community,

I'm trying to construct a Cypher query, which returns a subgraph from a specific node with arbitrary depth. The only constraint is, that it shouldn't continue from or include any node with a certain label.

More specific in my example:
There is a specific node with label submission (let's call it x) and a few nodes {y} connected with direction to the submission node x. Now I want to get the whole subgraph of y while I don't want to have x or anything beyond it.
I have no information about node or edge labels which are included in the subgraph of y.

I tried the following:

  1. match (x:submission)<--(y) where x.name="0A28VDC" call apoc.path.subgraphNodes(y, {labelFilter: "/submission"}) yield node return node,x,y

Problem: the labelfilter only returns subgraphs where the paths end at the node x. It would require something exluding submission and not searching beyond it, while including everything else. I couldn't find this functionality...

  1. match (x:submission)--(y)-[ ]-(z) WHERE x.name="0A28VDC" AND NOT z:submission return x,y,z

Problem: somehow this query doesn't terminate, probably because any y and z continuously appear in the search again. The problem is, that the subgraph I want to return has connections of any direction...

Somebody maybe has an idea how to solve this?

I would be so happy for any answer! :slight_smile:

Thank you and best wishes

Adrian

You may be able to use the blacklist filter symbol instead, so labelFilter:"-submission", that should exclude all :submission nodes from results.

Keep in mind that subgraphNodes() will only give you distinct nodes. It will not give you relationships. If you want relationships, you may want to use apoc.path.expandConfig() instead, possibly with uniqueness:'RELATIONSHIP_GLOBAL', that should get all connected nodes and relationships.