Hello guys,
I am very new to neo4j and I just started learning yesterday. I wanted to create a simple network from csv file that contains the following two columns.
I simply want to create a simple network so that column A is directed to column B.
LOAD CSV FROM 'file:///sampleticker.csv' AS line
CREATE (:main { name: line[0]}) -[:supplies_to]-> (:supplier {name: line[1]})
But when I do this, the network duplicates itself with multiple nodes having the same name. When AAPL exists for example, there should be only one as a node. I researched and tried to merge but without success.
So the thing you're tripping on is that :main and :supplier are not really supposed to be different kind of nodes, they're supposed to be some common node (such as :Company), it's only the role that the nodes are playing in that particular row that's changing, and we can handle that with variables.
Also, CREATE will create the entire pattern, and not look for existing nodes that you already added. You need to be using MERGE on the nodes, then MERGE on the relationship between them.
So you might try something like this:
LOAD CSV FROM 'file:///sampleticker.csv' AS line
MERGE (main:Company { name: line[0]})
MERGE (supplier:Company {name: line[1]})
MERGE (main)-[:supplies_to]->(supplier)