Neo4j函数“load csv with headers”不加载属性

时间:2017-08-17 15:39:37

标签: neo4j cypher load-csv

我尝试使用带有headers命令的加载CSV将以下节点加载到Neo4j中:

id  label   name
0   Person  Dave
1   Person  Boris
2   Person  Rita
3   Person  Daniel
4   Person  Papa
5   Person  Mama

我将Excel表格保存为:

CSV UTF-8 (Comma delimited) (*.csv)

,文件位置为:

 C:\Users\FY197T (2076902)\Documents\Neo4j\default.graphdb\import\nodes.csv

在编辑器中打开如下所示:

id;label;name
0;Person;Dave
1;Person;Boris
2;Person;Rita
3;Person;Daniel
4;Person;Papa
5;Person;Mama

要将节点加载到Neo4j,我使用:

load csv with headers from "file:///nodes.csv" as persons create (p1:Person {nodeID:persons.id, label: persons.label, name: persons.name})

但我得到的是:

Added 6 labels, created 6 nodes, completed after 105 ms.

所以有6个节点(因为我有6行),但它们都没有任何属性

我已尝试使用不同的分隔符保存文件,或手动添加引号。后者给出了:

there's a field starting with a quote and whereas it ends that quote
there seems to be characters in that field after that ending quote. That 
isn't supported. This is what I read: '"id"";"'

PS:我在stackoverflow上阅读了关于这个主题的所有其他帖子,但是我还没有解决它

修改

1

  load csv with headers from "file:///nodes.csv" as persons FIELDTERMINATOR ';' return persons.label

给出:

 persons.label
 (empty)
 (empty)
 (empty)
 (empty)
 (empty)
 (empty)

2

load csv with headers from "file:///nodes.csv" as persons FIELDTERMINATOR ';' return persons

给出:

persons
{
   "id": "0",
   "label": "Person",
   "name": "Dave"
}
{
   "id": "1",
  "label": "Person",
   "name": "Boris"
 }
an so on....

2 个答案:

答案 0 :(得分:2)

您可以尝试使用反引号:

    load csv with headers from "file:///nodes.csv" as persons FIELDTERMINATOR ';' return persons.`label`;

答案 1 :(得分:1)

当您使用;作为字段分隔符时,应指定FIELDTERMINATOR选项。这样:

使用此CSV文件:

id;label;name
0;Person;Dave
1;Person;Boris
2;Person;Rita
3;Person;Daniel
4;Person;Papa
5;Person;Mama

这个导入脚本:

load csv with headers from "file:///nodes.csv" as persons FIELDTERMINATOR ';'
create (p1:Person {nodeID:persons.id, label: persons.label, name: persons.name})

导入后,我在图表上运行了这个简单的查询:

MATCH (n) RETURN n

结果为文字:

╒═══════════════════════════════════════════════╕
│"n"                                            │
╞═══════════════════════════════════════════════╡
│{"name":"Dave","label":"Person","nodeID":"0"}  │
├───────────────────────────────────────────────┤
│{"name":"Boris","label":"Person","nodeID":"1"} │
├───────────────────────────────────────────────┤
│{"name":"Rita","label":"Person","nodeID":"2"}  │
├───────────────────────────────────────────────┤
│{"name":"Daniel","label":"Person","nodeID":"3"}│
├───────────────────────────────────────────────┤
│{"name":"Papa","label":"Person","nodeID":"4"}  │
├───────────────────────────────────────────────┤
│{"name":"Mama","label":"Person","nodeID":"5"}  │
└───────────────────────────────────────────────┘