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.

neo4j graph find all path from parent to each child without relationship

Hello guys,

I want to print all path present form parent node to child node for entire trees present in graph. Database contains Sr manager as root node.Database contains only single tree maintained in hierarchy there is no graph. Only 2 types of nodes exists Employee and Position. Employee node is connected to other employee node by :boss_of where as each employee has only one Position node connected with :has_power relationship. there is no connection/relationship between different positions. I want to print all paths present in following manner. Sr manager will always be present at the start of path Please see diagram.

Sr Manager 
Sr Manager -> Manager 
Sr Manager -> Manager -> jr developer
Sr Manager -> Manager -> sr developer
Sr Manager -> Manager -> tester
Sr Manager -> Manager -> tester -> BA
Sr Manager -> Manager -> tester -> BA -> jrBA 
Sr Manager -> Manager -> tester -> BA -> jrBA -> content writer[enter 

and so on .....

Apologies! there is a bit change in the graph structure there is one more type of node conencted to Employee labeled as Domain so in graph there are 3 types of nodes present Employee, Position and Domain , whereas both Position and Domain are conencted to Employee with :has_power and :has_ref relationship resp and there is no relation between Position and Domain

1 REPLY 1

shan
Graph Buddy

How about this:

MATCH (smanager:Position {name:"Sr Manager"})-[:HAS_POWER]->(smanageremployee:Employee)
MATCH p=(smanageremployee)-[:BOSS_OF*0..]->(e:Employee)
WITH p, nodes(p) AS employees
UNWIND employees AS employee
MATCH (manager:Position)-[:HAS_POWER]->(employee)
WITH p, collect(distinct manager.name) AS managersHierarchy
RETURN distinct managersHierarchy

You'd better put a limit on that BOSS_OF path as it may get expensive if you have a huge graph.