How to model a complex parent-child hierarchy data in Neo4j from a relational structure?

Hi All,

I am new to graph databases and need some help on modeling.
Let's assume, I have 3 sets of below CSV files with sample data:

file#1: (master file with unique nodeID's and their names)

nodeID, nodeName
1, A
2, B
3, C
4, D

file#2: parent-child relationships with all diff kind of relations between nodes i.e. recursive, self, bi-directional and/or with multiple parents etc. All 3 columns make it unique (composite pk)

startNode, endNode, nodeRelation
1, 2, x
2, 3, y
2, 4, y
4, 1, z
3, 2, x

file#3: All 3 columns make it unique (composite pk)

nodeID, exceptionCatg, exceptionReason
1, AAA, xyz
1, BB, xyz
2, AAA, cde
3, CCCC, mno

How to model the above structure ?

Mainly interested in searching for a specific nodeName as such that it would show all the upward/downward hierarhcy path along with the relationships from that node point onwards with search on nodeName to show paths with all matching names.

example:

Please help/suggest.

Thanks!

Try this:

merge (a:Person {name: "A"})
  merge (a1:Person {name: "B"})
  merge (a2:Person {name: "C"})
  merge (a3:Person {name: "D"})
  
  merge (a)-[:X]->(a1)
  merge (a1)-[:Y]->(a2)
  merge (a2)-[:X]->(a1)
  merge (a3)-[:Z]->(a)
  merge (a1)-[:Y]->(a3)
  
  merge (b:Exception {category: "AAA", reason: "xyz"})
  merge (a)-[:EXCEPTION]->(b)
  merge (b1:Exception {category: "BB", reason: "xyz"})
  merge (a)-[:EXCEPTION]->(b1)
  
  merge (b2:Exception {category: "AAA", reason: "cde"})
  merge (a1)-[:EXCEPTION]->(b2)
  
  merge (b3:Exception {category: "CCCC", reason: "mno"})
  merge (a2)-[:EXCEPTION]->(b3)

Match p = (a:Person)-[*..4]-(b) where a.name = "A"
return p

Result:

Thanks @ameyasoft !! Will give it a try.

However, could you please clarify how to model or join these 3 files ? I would first need to create model with nodes,edges, labels, properties etc and then load these 3 CSV files with respective attributes into each nodes/edges - labels/properties and then finally run cypher queries to generate above such graphs. Hence, also interested to learn how to model it at first place and how to load them ?

I was thinking like below :

Do this look okay or it needs to be done differently?

Thanks!

Check this link:

Yes, learned how to load the csv files. Just curious if the above model looks okay ?