# Problems matching a whole subgraph without knowledge about content

**URL:** <https://community.neo4j.com/t/problems-matching-a-whole-subgraph-without-knowledge-about-content/18906>\
**Category:** Cypher\
**Tags:** cypher\
**Created:** [May 19, 2020, 6:18pm UTC](https://community.neo4j.com/t/problems-matching-a-whole-subgraph-without-knowledge-about-content/18906 "2020-05-19T18:18:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![adrian.koegl](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/adrian.koegl/32/3823_2.png) [@adrian.koegl](https://community.neo4j.com/u/adrian.koegl)\
**Post date:** [May 19, 2020, 6:18pm UTC](https://community.neo4j.com/t/problems-matching-a-whole-subgraph-without-knowledge-about-content/18906/1 "2020-05-19T18:18:05Z")

</div>

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! 🙂

Thank you and best wishes

Adrian

---

<div class="post-metadata">

**Author:** ![andrew\_bowman](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/andrew_bowman/32/73_2.png) [@andrew\_bowman](https://community.neo4j.com/u/andrew_bowman)\
**Post date:** [May 19, 2020, 9:17pm UTC](https://community.neo4j.com/t/problems-matching-a-whole-subgraph-without-knowledge-about-content/18906/2 "2020-05-19T21:17:19Z")

</div>

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.
