Neo4j加载csv文件

时间:2015-10-03 13:29:39

标签: csv neo4j

我正在尝试按照"使用加载CSV&#34导入中的说明学习如何在Neo4j中导入csv文件; LearningNeo4j书的一章。代码我实现了以下内容:

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;

到目前为止一切正常但是当我尝试以这种方式建立关系时:

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

我无法匹敌。我只是简单地复制并通过了本书的代码,但我无法建立关系。有人可以帮助我吗?

P.S。 csv文件是:

{{1}}

修改

我只是复制你的代码,我获得了以下内容 the precedence of these operators

对不起,但是在你的链接中,我无法理解你是否正在做什么。

1 个答案:

答案 0 :(得分:1)

未创建关系上的type属性。所以你的比赛不会结束。

这是因为在您的标头中,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

另外,我建议您检查标签和索引是什么,以加快插入更大的数据集。

修改

我已将您的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 *;

图表似乎是正确创建的。您能否使用有关灰色图表的屏幕截图更新您的问题。

另请注意,您可能需要通过在浏览器控制台编辑器中发出:style reset命令来重置图表的样式。