# Help with getting a graph that i've created

**URL:** <https://community.neo4j.com/t/help-with-getting-a-graph-that-ive-created/55049>\
**Category:** Cypher\
**Tags:** apoc, cypher\
**Created:** [April 20, 2022, 8:15am UTC](https://community.neo4j.com/t/help-with-getting-a-graph-that-ive-created/55049 "2022-04-20T08:15:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![verachkaverachk](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/verachkaverachk/32/23510_2.png) [@verachkaverachk](https://community.neo4j.com/u/verachkaverachk)\
**Post date:** [April 20, 2022, 8:15am UTC](https://community.neo4j.com/t/help-with-getting-a-graph-that-ive-created/55049/1 "2022-04-20T08:15:17Z")

</div>

hello, I want to get all the nodes and relations that connected to subGraphInstance node, and I'm having troubles with that,  
the graph looks like this:  
 ![image](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/5/4/546d7a4a54c7434cc86dfaf82db776be279596c2.png)  
and I want to find it and all it's relations by the name of the subgraph  
unfortunately all i'm able to get is this when I tried to run a query that goes like this:  
MATCH (n:SubGraphInstance)-[r:FROM\_GRAPH]-\>(c:CellInstance)-[g:FROM\_TYPE]-\>(t:CellType)-[k:CELL\_TYPE\_FUNCTION]-\>(f:Function)-[v:FUNCTIONS\_VARS]-\>(va:Variable)  
WHERE n.name= "batman"

please help me with this guys!  
and have a great day!!

:

 ![image](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/f/b/fb13458b56f34824ee2e58c78cff3e20b910e55b.png)

---

<div class="post-metadata">

**Author:** ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)\
**Post date:** [April 20, 2022, 9:23am UTC](https://community.neo4j.com/t/help-with-getting-a-graph-that-ive-created/55049/2 "2022-04-20T09:23:48Z")

</div>

You have specified a very specific pattern to match. It looks like two paths matched and where returned. You could try a more generalized pattern to obtain all the paths, such as:

```auto
MATCH p=(n:SubGraphInstance)-[*]-()
WHERE n.name= "batman"
RETURN p

```

I see from the data, that there looks to be four paths originating from the Batman node and terminating on a ‘Variable’ node that has only an incoming FUNCTIONS\_VARS relationship type. We can use that to get more targeted and get just those paths. The following looks for paths starting from Batman and terminating on a ‘Variable’ node, I.e, no outgoing relationships.

```auto
MATCH p=(n:SubGraphInstance)-[*]-(va:Variable)
WHERE n.name= "batman
AND not exists ( (va)-[]->() )
RETURN p

```

There are also APOC methods to retrieve subgraphs originating from a node. Maybe one of the APOC experts will provide such a solution.

---

<div class="post-metadata">

**Author:** ![verachkaverachk](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/verachkaverachk/32/23510_2.png) [@verachkaverachk](https://community.neo4j.com/u/verachkaverachk)\
**Post date:** [April 20, 2022, 9:29am UTC](https://community.neo4j.com/t/help-with-getting-a-graph-that-ive-created/55049/3 "2022-04-20T09:29:07Z")

</div>

thank you so much!! looks like it works :)!!

---

<div class="post-metadata">

**Author:** ![verachkaverachk](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/verachkaverachk/32/23510_2.png) [@verachkaverachk](https://community.neo4j.com/u/verachkaverachk)\
**Post date:** [April 20, 2022, 10:44am UTC](https://community.neo4j.com/t/help-with-getting-a-graph-that-ive-created/55049/4 "2022-04-20T10:44:15Z")

</div>

and can you please explain me about the asterisk in these two cases? I do understand that it's connected to relationships, but how exactly?

---

<div class="post-metadata">

**Author:** ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)\
**Post date:** [April 20, 2022, 11:52am UTC](https://community.neo4j.com/t/help-with-getting-a-graph-that-ive-created/55049/5 "2022-04-20T11:52:26Z")

</div>

Glad to. When you specify a pattern as below, it is requiring the two nodes to be exactly one relationship apart.

```auto
Match ()-[]-()

```

Sometimes you want to match a pattern, but you don’t want to specify the exact sequence of relationships between two nodes. In such a case, you can use variable length patterns, where you specify the number of relationships instead. The asterisk is the syntax that indicates a variable number relationships between two nodes. The match below specifies paths between two nodes that has any number of relationships between the two nodes.

```auto
Match ()-[*]-()

```

You can also set upper and lower bounds on the number of hops, as below, where the min is 2 relationships and the max is 6 relationships. Either the min or max is optional, allowing you to set only an upper or lower limit as well.

```auto
Match ()-[*2…6]-()

```

If you want to read more, try reviewing section 4.3 and the sections around it.

> **[MATCH - Cypher Manual](https://neo4j.com/docs/cypher-manual/4.4/clauses/match/#varlength-rels)**
>
> The \`MATCH\` clause is used to search for the pattern described in it.

---

<div class="post-metadata">

**Author:** ![verachkaverachk](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/verachkaverachk/32/23510_2.png) [@verachkaverachk](https://community.neo4j.com/u/verachkaverachk)\
**Post date:** [April 20, 2022, 12:01pm UTC](https://community.neo4j.com/t/help-with-getting-a-graph-that-ive-created/55049/6 "2022-04-20T12:01:05Z")

</div>

Awesome! thank you so much for your clear answers ,I will also review section 4.3 that you added to understand more how everything works.  
and if i will have more questions I will ask :)
