Reputation: 1
I'm new to Neo4j and doing some practice on Neo4j.
I have a csv file with headers:
product,material
aa,bb
aa,cc
cc,bb
dd,aa
I want to import it to N4j and create a relationship named "from" and want it to a graph like this: graph Initially I think it's pretty easy and I struggled for 2ds and give up... I need a help. my code is here:
load csv with headers from"files:\\test.csv" as file
merge (p:product {id:file.product})
merge (m:material {id:file.material})
create (p)-[:from]->(m)
and then the result is here:graph2
so,
1.How can I make "aa" creat only one node?
2.How can I make the node show "aa""bb"...rather than numbers?
3.btw,in n4j handbook,whats difference between "import tool" and "load csv"?
Upvotes: 0
Views: 221
Reputation: 30397
The problem is you're using different labels in your creation queries.
Line 2 in your CSV creates a :material node with id 'cc'. While you have 'cc' as your id in line 3, it's for a :product node. When executing on line 3, no such :product nodes exist with id 'cc' (there's a :material node with that id, but since the label is different the match fails), so a new :product node is created.
Likewise with 'aa'. Lines 1 and 2 in your CSV merge a :product node 'aa', but in line 4 the id is for a :material node. Again, the labels are different, so it won't reuse your previously created node.
To achieve your desired graph, if all the ids are meant to refer to the same node, then the label in the merge has to be the same too.
Upvotes: 1