# Modification of apoc.subgraphAll procedure

**URL:** <https://community.neo4j.com/t/modification-of-apoc-subgraphall-procedure/65575>\
**Category:** Procedures & APOC\
**Tags:** apoc, cypher\
**Created:** [January 2, 2024, 8:35am UTC](https://community.neo4j.com/t/modification-of-apoc-subgraphall-procedure/65575 "2024-01-02T08:35:58Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sr602008](https://avatars.discourse-cdn.com/v4/letter/s/b38774/32.png) [@sr602008](https://community.neo4j.com/u/sr602008)\
**Post date:** [January 2, 2024, 8:35am UTC](https://community.neo4j.com/t/modification-of-apoc-subgraphall-procedure/65575/1 "2024-01-02T08:35:58Z")

</div>

I am doing a project in which I am required to return the path or nodes in a path from a particular start node.I have manually passed the start node to the query.I need to continue down the path till the relation propert 'Action' between two consecutive nodes are "ODC". If the 'Action' property is "ODSN",I have to break from the particular path and return the next node alone separately.I am required to process all the paths from a particular start node in this manner.I had tries using the apoc.subgraphAll procdure but i am not detting the desired result

MATCH (c:Customer {customer\_id: 4})  
CALL apoc.path.subgraphAll(c, {  
relationshipFilter: "\>",  
minLevel: 1  
})  
YIELD nodes, relationships  
UNWIND relationships as rel  
WITH nodes, rel  
WHERE rel.Action = 'ODC'  
RETURN DISTINCT nodes

Is there another method to approach this or should be using another apoc procedure?

---

<div class="post-metadata">

**Author:** ![hakan.lofqvist1](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/hakan.lofqvist1/32/10877_2.png) [@hakan.lofqvist1](https://community.neo4j.com/u/hakan.lofqvist1)\
**Post date:** [January 2, 2024, 9:01am UTC](https://community.neo4j.com/t/modification-of-apoc-subgraphall-procedure/65575/2 "2024-01-02T09:01:55Z")

</div>

In many cases you can use quantified path patterns for this [Concepts - Cypher Manual](https://neo4j.com/docs/cypher-manual/current/patterns/concepts/#quantified-path-patterns)

So something like this

```auto
MATCH (:Customer {customer_id: 4}) (
    (c)-[rel]->(a)
    WHERE rel.Action = 'ODC'
){1,5}
RETURN c,rel,a

```

You may have to unwind or do other tricks to get the result you want since `c`, `rel` and `a` will be lists.

---

<div class="post-metadata">

**Author:** ![sr602008](https://avatars.discourse-cdn.com/v4/letter/s/b38774/32.png) [@sr602008](https://community.neo4j.com/u/sr602008)\
**Post date:** [January 2, 2024, 9:46am UTC](https://community.neo4j.com/t/modification-of-apoc-subgraphall-procedure/65575/3 "2024-01-02T09:46:28Z")

</div>

> [@hakan.lofqvist1](#):
>
> ```auto
> MATCH (:Customer {customer_id: 4}) (
> (c)-[rel]->(a)
> WHERE rel.Action = 'ODC'
> ){1,5}
> RETURN c,rel,a
> 
> ```

in the query that you have provided, can you give the significance of {1,5}. Does it denote the minimum and maximum number of hops?

---

<div class="post-metadata">

**Author:** ![hakan.lofqvist1](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/hakan.lofqvist1/32/10877_2.png) [@hakan.lofqvist1](https://community.neo4j.com/u/hakan.lofqvist1)\
**Post date:** [January 2, 2024, 10:58am UTC](https://community.neo4j.com/t/modification-of-apoc-subgraphall-procedure/65575/4 "2024-01-02T10:58:29Z")

</div>

Yes, {1,5} is the number of times the pattern `(c)-[rel]->(a)` can occur. So adjust to what your shortest vs longest path of interest would be.

---

<div class="post-metadata">

**Author:** ![sr602008](https://avatars.discourse-cdn.com/v4/letter/s/b38774/32.png) [@sr602008](https://community.neo4j.com/u/sr602008)\
**Post date:** [January 2, 2024, 11:02am UTC](https://community.neo4j.com/t/modification-of-apoc-subgraphall-procedure/65575/5 "2024-01-02T11:02:55Z")

</div>

Actually my data model consists of arbitrary relationship labels .The depth of each path is not constant or defined.The relationship between any two nodes changes multiple times in each path.So i cannot define a particular value.Could you please suggest another method other than this,if possible.

---

<div class="post-metadata">

**Author:** ![sr602008](https://avatars.discourse-cdn.com/v4/letter/s/b38774/32.png) [@sr602008](https://community.neo4j.com/u/sr602008)\
**Post date:** [January 2, 2024, 11:09am UTC](https://community.neo4j.com/t/modification-of-apoc-subgraphall-procedure/65575/6 "2024-01-02T11:09:52Z")

</div>

Considering i have to obtain all the nodes in the subgraph of n:Customer with customer\_id 4....Starting from this node i have to traverse each node in the path originating with 'n' and break or stop traversing down the path when a relationship with 'Action' property is set to "ODC"._Each relationship definitely has this property in my model._  
After breaking from one path I have to check the other paths originating from this node 'n'.I have to repeat this process till all paths are traversed and return the relevant nodes.  
I am required to store these nodes in a data structure in java.  
Any guidance on how to approach this would be very helpful.Thanks
