Reputation: 2064
I can't figure out how to create links out of CSV tables in Neo4j. I've read several parts of the manual (match, loadCSV, etc), that free book, and several tutorials I've found. None of them seems to contemplate my use case (which is weird, because I think it's a pretty simple use case). I've tried adapting the code they have in all sorts of ways, but nothing seems to work.
So, I have three CSV tables: parent companies, child companies, and parent-child pairs. I begin by loading the first two tables (and that works fine - all the properties are there, all the info is correct):
LOAD CSV FROM "file:/C:/Users/thiago.marzagao/Desktop/CSVs/children.csv" AS node
CREATE (:Children {id: node[0], name: node[1]})
LOAD CSV FROM "file:/C:/Users/thiago.marzagao/Desktop/CSVs/parents.csv" AS node
CREATE (:Parent {id: node[0], name: node[1]})
Now, here's the structure of the third table:
child_id,parent_id
Here's some of the things I've tried:
LOAD CSV FROM "file:/C:/Users/thiago.marzagao/Desktop/CSVs/link.csv" AS rels
MATCH (FROM {Parent: rels[1]}), (TO {Children: rels[0]})
CREATE (Parent)-[:OWNS]->(Children)
This doesn't give me an eror, but it returns zero rows.
LOAD CSV FROM "file:/C:/Users/thiago.marzagao/Desktop/CSVs/link.csv" AS rels
MATCH (FROM {id: rels[1]}), (TO {id: rels[0]})
CREATE (Parent)-[:OWNS]->(Children)
This doesn't give me an error, but it just returns a bunch of pairs of empty nodes. So, it creates the links, but somehow it doesn't link the actual nodes.
LOAD CSV FROM "file:/C:/Users/thiago.marzagao/Desktop/CSVs/link.csv" AS rels
MATCH (FROM {Parent.id: rels[1]}), (TO {Children.id: rels[0]})
CREATE (Parent)-[:OWNS]->(Children)
This gives me a syntax error (Neo.ClientError.Statement.InvalidSyntax
)
I also tried several variations of the code blocks above, but to no avail. So, what am I doing wrong? (I'm on Neo4j 2.1.6, in case that matters.)
Upvotes: 1
Views: 66
Reputation: 20175
In your cypher statement, you are not referencing to the same identifiers used in the MATCH for creating the relationship, so he will just create new empty nodes :
Look at the difference :
MATCH (FROM {id: rels[1]}), (TO {id: rels[0]})
CREATE (Parent)-[:OWNS]->(Children)
Instead it should be :
LOAD CSV FROM "file:/C:/Users/thiago.marzagao/Desktop/CSVs/link.csv" AS rels
MATCH (Parent {id: rels[1]}), (Children {id: rels[0]})
CREATE (Parent)-[:OWNS]->(Children)
Upvotes: 2