neo4j cypher query for hierarchical relationship matching -


i'm modeling set of nodes has hierarchical relationships (as parent relationship) additionally non-hierarchical relationship.

let's it's family tree relationships birth country each person, simplicity

so each birth country node , each person node, , might create relationship in cypher as:

start parent=node(123), child=node(456) create parent-[:parent]->child; 

and

start person=node(123), country=node(789) create person-[:born_in]->country; 

what i'd is, example, list of folks don't have ancestors england, or folks have ancestor japan, or like. feel should reasonable query, new cypher , haven't clue how construct it.

update ** after more extensive testing of cases, i've found query doesn't work right in some. given child 1 parent england , grandparent not england, query children without ancestors england incorrectly returns child parent england. looks way i've written query, return grandparent having null relationship england. query follows:

start n=node(*), ancestor=node(123) match n-[r:parent*]->o-[b?:born_in]->ancestor b null  return distinct n; 

if person's ancestors born in country in question, works fine.

you can use variable length relation include children/ancestors. picked "folks have ancestor japan":

start country=<lookup japan> match (child)-[:parent*0..5]->(parent)-[:born_in]->(country) return child 

note: have not tried logically should it. picked random depth of 5.

match a-[:parent]->b-[:born_in]->z  

as mentioned in example should find persons (a) have parent born in z

if have data set handy on console.neo4j.org maybe, take @ what's happening.


Comments

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -