cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to get nodes exlude nodes behind node with some property?

Hi guys!
I have this graph

create (n:Point{id:1,a:10,closed:false})
create (n)-[:PARENT]->(n1:Point{id:2,a:10,closed:true})-[:CHILD]->(n)
create (n)-[:PARENT]->(n2:Point{id:3,a:10,closed:false})-[:CHILD]->(n)
create (n)-[:PARENT]->(n3:Point{id:4,a:10,closed:false})-[:CHILD]->(n)
create (n1)-[:PARENT]->(n4:Point{id:5,a:10,closed:false})-[:CHILD]->(n1)
create (n1)-[:PARENT]->(n5:Point{id:6,a:10,closed:false})-[:CHILD]->(n1)
create (n2)-[:PARENT]->(n6:Point{id:7,a:10,closed:false})-[:CHILD]->(n2)
create (n6)-[:PARENT]->(n7:Point{id:8,a:10,closed:true})-[:CHILD]->(n6)
create (n7)-[:PARENT]->(n8:Point{id:9,a:10,closed:false})-[:CHILD]->(n7)
create (n7)-[:PARENT]->(n9:Point{id:10,a:10,closed:true})-[:CHILD]->(n7)
create (n7)-[:PARENT]->(n10:Point{id:11,a:10,closed:true})-[:CHILD]->(n7)

And I want to get this nodes from image below and made some mutations with them, but I couldnt understand how to exclude nodes behind nodes with field "closed:true"

I'm trying to do this

MATCH v=(n:Point{id:1})-[:PARENT*]->(f:Point)
WHERE f.closed = false RETURN v

And I get all the graph. I understand why I get whole graph, but I don't know how to exlude nodes I need. May you give an information or a query which will help me to understand the concept how to work with this problem?

Thanks for you help

1 ACCEPTED SOLUTION

Bennu
Graph Fellow

Hi @alexander.kaluzhskiy ,

Yoou don't really need the CHILD relationship, you can just manage with the direction of parent. Eventually you may like adding an specific label fo point with closed False in order to speed up this kind of query on big databases with APOC subgraph.

Anyway, you are looking for something like :

MATCH v=(:Point{id:1})-[:PARENT*]->(:Point)
WHERE all(n in nodes(v) where n.closed = false) 
RETURN v

Bennu

View solution in original post

2 REPLIES 2

Bennu
Graph Fellow

Hi @alexander.kaluzhskiy ,

Yoou don't really need the CHILD relationship, you can just manage with the direction of parent. Eventually you may like adding an specific label fo point with closed False in order to speed up this kind of query on big databases with APOC subgraph.

Anyway, you are looking for something like :

MATCH v=(:Point{id:1})-[:PARENT*]->(:Point)
WHERE all(n in nodes(v) where n.closed = false) 
RETURN v

Bennu

Wow, thank you so much! I think I start to understand the concept how to work with filters