Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
04-29-2020 11:41 AM
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.
This is what I am trying to achieve
Any help would be immensely appreciated.
Thank you very much!
Solved! Go to Solution.
04-29-2020 04:13 PM
I see! This makes sense to merge them into a node called company first and then create the relationship. Thank you so much! It looks perfect now.
04-29-2020 11:51 AM
Hello,
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.
https://neo4j.com/docs/cypher-manual/current/clauses/merge/
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)
04-29-2020 04:13 PM
I see! This makes sense to merge them into a node called company first and then create the relationship. Thank you so much! It looks perfect now.
All the sessions of the conference are now available online