# Is it possible to filter nodes on a specific level within a path

**URL:** <https://community.neo4j.com/t/is-it-possible-to-filter-nodes-on-a-specific-level-within-a-path/2230>\
**Category:** Neo4j Graph Platform\
**Created:** [October 3, 2018, 8:24am UTC](https://community.neo4j.com/t/is-it-possible-to-filter-nodes-on-a-specific-level-within-a-path/2230 "2018-10-03T08:24:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![michael.horak](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/michael.horak/32/480_2.png) [@michael.horak](https://community.neo4j.com/u/michael.horak)\
**Post date:** [October 3, 2018, 8:24am UTC](https://community.neo4j.com/t/is-it-possible-to-filter-nodes-on-a-specific-level-within-a-path/2230/1 "2018-10-03T08:24:15Z")

</div>

Hello,  
I would like to ask if there is a way to filter a specific level in a path.

eg. MATCH p=(n {name:'John'})-[:KNOWS]-\>(level 1)-[:ADDRESS]-\>(level 2)-[:COUNTRY]-\>(level 3) RETURN p;

I would like to filter the level 1 and return only the level 2, level 3 (all the following levels).

thank you

---

<div class="post-metadata">

**Author:** ![Benoit](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/benoit/32/551_2.png) [@Benoit](https://community.neo4j.com/u/Benoit)\
**Post date:** [October 3, 2018, 10:13am UTC](https://community.neo4j.com/t/is-it-possible-to-filter-nodes-on-a-specific-level-within-a-path/2230/2 "2018-10-03T10:13:22Z")

</div>

Hi Michael,

Why are you defining a path if you don't want to use it ?

From what I understand, your query can be written like that :

```auto
MATCH (n {name:'John'})-[:KNOWS]->(lvl1)-[:ADDRESS]->(lvl2)-[:COUNTRY]->(lvl3) 
WHERE lvl1.value = 'XXXX' / /your level 1 filter
RETURN lvl2, lvl3 // return only the level 2, level 3

```

Cheers

---

<div class="post-metadata">

**Author:** ![michael.horak](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/michael.horak/32/480_2.png) [@michael.horak](https://community.neo4j.com/u/michael.horak)\
**Post date:** [October 3, 2018, 11:04am UTC](https://community.neo4j.com/t/is-it-possible-to-filter-nodes-on-a-specific-level-within-a-path/2230/3 "2018-10-03T11:04:01Z")

</div>

Hello,

The problem is that this query is dynamically generated so I don't know in advance which level should be filtered and on which value I should filter (defined by a user).

I want to use a path because I need to return all nodes and relations from the given pattern, except a given level so I could explicitly define a query:

MATCH (n {name:'John'})-[r1:KNOWS]-\>(level 1)-[r2:ADDRESS]-\>(level 2)-[r3:COUNTRY]-\>(level 3) RETURN r2, level2, r3, level3;

but I would like to ask if there is a way to do the same thing while using the path (return only path) because it simplifies the result parsing for me.

Thank you,  
Michael

---

<div class="post-metadata">

**Author:** ![Benoit](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/benoit/32/551_2.png) [@Benoit](https://community.neo4j.com/u/Benoit)\
**Post date:** [October 3, 2018, 11:17am UTC](https://community.neo4j.com/t/is-it-possible-to-filter-nodes-on-a-specific-level-within-a-path/2230/4 "2018-10-03T11:17:23Z")

</div>

Re,

It's possible to do, but you can have some bad impact on the performances :

```auto

MATCH p=(n {name:'John'})-[:KNOWS]->(level 1)-[:ADDRESS]->(level 2)-[:COUNTRY]->(level 3) 
WHERE head(tail(nodes(p))).value = 'XXXX' // your level 1 filter
RETURN tail(tail(nodes(p))), tail(tail(relationships(p))) // return all the level except the root and lvl1

```

In the `WHERE` clause, Neo4j is working on an array, so it can't use any indexes.
