Is this a main node for each json imported, if so, how will you differentiate each main node? Will you use a unique ‘id’ or ‘name’ property?
@glilienfield hi there
There is only one json file and not more than one json.
You can use the existing json itself, and want to create a main node ( top node) named as main. And that top node should connect with each head node in that json file.
I hope it's clear
Try this:
MERGE(main:Entity{name:'main'})
WITH main
CALL apoc.load.json("file:///sample.json") YIELD value
UNWIND value.relations as relation
MERGE (head:Entity {name: relation.head})
MERGE (tail:Entity {name: relation.tail})
MERGE (head)-[:HAS_MAIN]->(main)
WITH head, relation, tail, toUpper(replace(relation.type, " ", "_")) as type
CALL apoc.create.relationship(head, type, {}, tail) YIELD rel
RETURN count(rel)
There are only 15 relationships incoming to the main node. This is because your data only has 15 distinct head nodes.
cheers @Estelle as expected. i really appreciate your time and patience for helping me out.
+1 kudos to you..
@glilienfield thank you very much! it worked!