简体   繁体   English

Neo4j加载CSV文件

[英]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. 我正在尝试按照LearningNeo4j书籍的“使用加载CSV导入”一章中的说明,学习如何在Neo4j中导入csv文件。 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: PS csv文件为:

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. 关系上的type属性未创建。 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 : 这是因为在标题中, Relationship列的后面紧跟一个空格,您需要用空格反引号:

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 : 我已将您的csv上传到要点,并在Neo4j控制台中( 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. 另请注意,也许您需要通过在浏览器控制台编辑器中发出:style reset命令来重置图形的:style reset

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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