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.

Newbie question, configuring simple network

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.

2X_e_e760ede164da9ab1bbe9aee7acbfb6ac6b9600f5.png

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

2X_f_f7c7e51e99178bb5433001db21e5b67ed938d02b.png

Any help would be immensely appreciated.

Thank you very much!

1 ACCEPTED SOLUTION

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.

View solution in original post

2 REPLIES 2

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)

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.