# apoc.path.expandConfig, node whitelisting

**URL:** <https://community.neo4j.com/t/apoc-path-expandconfig-node-whitelisting/62628>\
**Category:** Procedures & APOC\
**Created:** [May 22, 2023, 9:59pm UTC](https://community.neo4j.com/t/apoc-path-expandconfig-node-whitelisting/62628 "2023-05-22T21:59:25Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![shsamardar](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/shsamardar/32/33508_2.png) [@shsamardar](https://community.neo4j.com/u/shsamardar)\
**Post date:** [May 22, 2023, 9:59pm UTC](https://community.neo4j.com/t/apoc-path-expandconfig-node-whitelisting/62628/1 "2023-05-22T21:59:25Z")

</div>

Hello

I want to use apoc.path.expandConfgi like below.

I have Nodes with these labels  
1- PartRevision  
2- Occurrence: some of Occurrence nodes have extra labels :Base/Deluxe. Occurrences nodes have both Base and Deluxe labels

I want to have a whitelistNode that are for PartREvision and only Occurrences that have 'Deluxe ' labels. I want Occurrences that have 'Base' label were blacklisted.

I am trying something like below. I am getting error on line 3 that variable t is not defined.

Is my Union correct for the purpose of generating whiltelistNodes? or there is a better to do whitelist nodes ? I prefer to have blacklisted implemented that I can add more nodes that have other labels. How can I blacklist nodes that have ONLY Occurrence/Base and don't have Deluxe ?  
( reminder that soem occurences have both Base/Deluxe)

also how can i pass t to apoc.path.config ?

```auto
match ( t:PartRevision) where t.name = 'CROSSKART_DC' 
match ( o:Deluxe ) return o union match (p:PartRevision) return p as X 
WITH t , collect ( X) as AllowedOccurences
CALL apoc.path.expandConfig(
    t,
    {
        relationshipFilter:"HAS_PARENT|`Latest Working`",
        uniqueness: "NODE_GLOBAL",
        whitelistNodes : AllowedOccurences
    }) YIELD path
RETURN path

```

---

<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:** [May 22, 2023, 10:47pm UTC](https://community.neo4j.com/t/apoc-path-expandconfig-node-whitelisting/62628/2 "2023-05-22T22:47:13Z")

</div>

Try this:

```auto
match (t:PartRevision) 
where t.name = 'CROSSKART_DC'
call {
    match (x:Deluxe) 
    return x
    union 
    match (x:PartRevision) 
    return x
}
WITH t, collect (x) as AllowedOccurences
CALL apoc.path.expandConfig(
t,
{
    relationshipFilter:"HAS_PARENT|Latest Working",
    uniqueness: "NODE_GLOBAL",
    whitelistNodes : AllowedOccurences
}) YIELD path
RETURN path

```

If you are using version 5, the following should work the same:

```auto
match (t:PartRevision) 
where t.name = 'CROSSKART_DC'
match (x:Deluxe|PartRevision) 
WITH t, collect (x) as AllowedOccurences
CALL apoc.path.expandConfig(
t,
{
    relationshipFilter:"HAS_PARENT|Latest Working",
    uniqueness: "NODE_GLOBAL",
    whitelistNodes : AllowedOccurences
}) YIELD path
RETURN path

```

With version 4, the following should work too:

```auto
match (t:PartRevision) 
where t.name = 'CROSSKART_DC'
match (x) where x:Deluxe or x:PartRevision
WITH t, collect (x) as AllowedOccurences
CALL apoc.path.expandConfig(
t,
{
    relationshipFilter:"HAS_PARENT|Latest Working",
    uniqueness: "NODE_GLOBAL",
    whitelistNodes : AllowedOccurences
}) YIELD path
RETURN path

```

---

<div class="post-metadata">

**Author:** ![shsamardar](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/shsamardar/32/33508_2.png) [@shsamardar](https://community.neo4j.com/u/shsamardar)\
**Post date:** [May 31, 2023, 11:05pm UTC](https://community.neo4j.com/t/apoc-path-expandconfig-node-whitelisting/62628/3 "2023-05-31T23:05:50Z")

</div>

Thank you Gary

what is difference between using labelFilter in below and your suggestions with having explicit matches ?

or better question what will be dfference for using WhiteListNodes compared to labelFilter?

match ( t:PartRevision) where t.name = 'CROSSKART\_DC'  
WITH t  
CALL apoc.path.expandConfig(  
t,  
{  
labelFilter:"PartRevision, Deluxe",  
relationshipFilter:"HAS\_PARENT\<, +`Latest Working`\> | -`Engineering Released`\>",  
uniqueness: "NODE\_GLOBAL",  
minLevel : 1,  
maxLevel : 3,  
bfs : false  
}) YIELD path  
RETURN path , length(path ) as hops  
order by hops

---

<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:** [June 1, 2023, 4:01am UTC](https://community.neo4j.com/t/apoc-path-expandconfig-node-whitelisting/62628/4 "2023-06-01T04:01:48Z")

</div>

I was just following your initial query to make the syntax work. I think in your case, both implementation will provide the same results, as the the white node list is comprised of all nodes with the same two labels as you have in your "allow" node labels. In terms of performance, I would think your implementation with labels will be more efficient, as it eliminates the need to query to get the specific nodes and to compare each path node to the nodes in the allow list. The label filtering will be incorporated as part of the transversal operation, so it should not add much overhead.

---

<div class="post-metadata">

**Author:** ![bennu\_neo](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/bennu_neo/32/27616_2.png) [@bennu\_neo](https://community.neo4j.com/u/bennu_neo)\
**Post date:** [June 3, 2023, 9:26pm UTC](https://community.neo4j.com/t/apoc-path-expandconfig-node-whitelisting/62628/5 "2023-06-03T21:26:46Z")

</div>

Hi @shsamardar,

Keep into consideration that querying nodes first in order to use them as a list will include a memory overhead due to the need of an explicit eager collection. Using label filters, conditions will be evaluated runtime.

---

<div class="post-metadata">

**Author:** ![bennu\_neo](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/bennu_neo/32/27616_2.png) [@bennu\_neo](https://community.neo4j.com/u/bennu_neo)\
**Post date:** [June 5, 2023, 8:47am UTC](https://community.neo4j.com/t/apoc-path-expandconfig-node-whitelisting/62628/6 "2023-06-05T08:47:41Z")

</div>

Hi @shsamardar ,

Are the has parent and latest working releationships only connecting PartRevision and Occurrences? if is that the case, this should work. If not, hopefully ill give you an idea of the nodeFilter usage.

```auto
MATCH( t:PartRevision) where t.name = 'CROSSKART_DC' 
CALL apoc.path.expandConfig(
    t,
    {
        relationshipFilter:"HAS_PARENT|`Latest Working`", //You may like to add directions
        labelFilter : "+Deluxe|+PartRevision"
        uniqueness: "NODE_GLOBAL"
    }) YIELD path
RETURN path

```
