简体   繁体   中英

Neo4j load csv file

I'm trying to learn how import csv files in Neo4j following the instructions in the "Importing using Load CSV" chapter of the LearningNeo4j book. The code i'm implementing is the following:

load csv with headers from 
"file:C:/wamp/www/fantapappa/nodes.csv"
as nodes
create (n {id: nodes.Node, name: nodes.Name, type: nodes.Label})
return n

load csv with headers from 
"file:C:/wamp/www/fantapappa/rels.csv" 
as rels 
match (from {id:rels.From}), (to {id: rels.To})
create from-[:REL {type: rels.'Relationship'}]->to
return from, to

match (m {type:"Male"}), (f {type:"Female"})
set m:Male, f:Female
return m,f

so far all is ok but when i try to build the relationship in this way:

match (n)-[r1 {type:"MOTHER_OF"}]->(m), (s)-[r2 {type:"FATHER_OF"}]->(t)
create n-[:MOTHER_OF]->m, s-[:FATHER_OF]->t
return *;

match ()-[r:REL]-() delete r;

I can not match anything. I have simply copy and past the code of the book but I'm not able to create relationships. Can some one help me?

PS The csv files are:

nodes.csv
Node,Name,Label
1,Amada Emory,Female
2,Rana Seely,Female
3,Detra Thatcher,Female
4,Melda Reza,Female
5,Shana Willems,Female
6,Sharonda Peele,Female
7,Dagny Agee,Female
8,Tisa Woodman,Female
9,Shelba Mutcheler,Female
10,Anderson Spagnola,Male
11,Pamela Forward,Female
12,Melva Fairchild,Female
13,Antione Selman,Male
14,Carmela Cali,Female
15,Fairy Daughtery,Female
16,Stefany Mcamis,Female
17,Kermit Meaney,Male
18,Williemae Dossantos,Female
19,Marth Sparling,Female
20,Jarvis Noland,Male

rels.csv
From,Name,Relationship ,To,Name
1,Amada Emoroy,MOTHER_OF,11,Pamala Forward
1,Amada Emoroy,MOTHER_OF,12,Melva Fairchild
1,Amada Emoroy,MOTHER_OF,13,Antione Selman
2,Rana Seely,MOTHER_OF,14,Carmelia Cali
2,Rana Seely,MOTHER_OF,15,Fairy Daughtery
2,Rana Seely,MOTHER_OF,16,Stefany Mcamis
3,Detra Thatcher,MOTHER_OF,17,Kermit Meaney
3,Detra Thatcher,MOTHER_OF,18,Williemae Dossantos
3,Detra Thatcher,MOTHER_OF,19,Marth Sparling
10,Anderson Spagnola,FATHER_OF,20,Jarvis Noland
14,Carmelia Cali,MOTHER_OF,1,Amada Emory
11,Pamela Forward,MOTHER_OF,2,Rana Seely
11,Pamela Forward,MOTHER_OF,3,Detra Thatcher
12,Melva Fairchild,MOTHER_OF,4,Melda Reza
12,Melva Fairchild,MOTHER_OF,5,Shana Willems
12,Melva Fairchild,MOTHER_OF,6,Sharonda Peele
17,Kermit Meaney,FATHER_OF,7,Dagny Agee
13,Antione Selman,MOTHER_OF,8,Tisa Woodman
13,Antione Selman,MOTHER_OF,9,Shelba Mutchler
20,Jarvis Noland,FATHER_OF,1,Amada Emory

EDIT

im just copying your code and I obtain the following 在此处输入图片说明

I m sorry but in your link I can not understand very well wath are you dooing.

The type property on the relationships is not created. So your match will not conclude.

This is because in your headers, the Relationship column has a space just after, you need to backtick the column name with the space :

rels.`Relationship `

-

load csv with headers from 
"file:C:/wamp/www/fantapappa/rels.csv" 
as rels 
match (from {id:rels.From}), (to {id: rels.To})
create from-[:REL {type: rels.`Relationship `}]->to
return from, to

Also I would recommend you to check what labels and indexes are, for speeding up the insert of larger datasets.

EDIT

I have uploaded your csv's to a gist and ran the whole process in a Neo4j Console here http://console.neo4j.org/r/hrao50 :

LOAD CSV WITH HEADERS FROM "https://gist.githubusercontent.com/ikwattro/2a38a2f71a7ebc8a6681/raw/da5b47ceab9a9d93f62a12ee1fe8224788c0d861/nodes.csv"
AS nodes
create (n {id: nodes.Node, name: nodes.Name, type: nodes.Label})
return n

LOAD CSV 
WITH HEADERS FROM "https://gist.githubusercontent.com/ikwattro/2a38a2f71a7ebc8a6681/raw/da5b47ceab9a9d93f62a12ee1fe8224788c0d861/rels.csv" 
AS rels
match (from {id:rels.From}), (to {id: rels.To})
create from-[:REL {type: rels.`Relationship `}]->to
return from, to

MATCH (m { type:"Male" }),(f { type:"Female" })
SET m:Male, f:Female
RETURN m,f

match (n)-[r1 {type:"MOTHER_OF"}]->(m), (s)-[r2 {type:"FATHER_OF"}]->(t)
create n-[:MOTHER_OF]->m, s-[:FATHER_OF]->t
return *;

And the graph seems to be created correctly. Can you update your question with a screenshot about your gray graph.

Please note also that maybe you need to reset the styling of your graph by issuing the :style reset command in the browser console editor.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM