2

我尝试使用 load CSV with headers 命令将以下节点加载到 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....
4

2 回答 2

2

您可以尝试使用反引号:

    load csv with headers from "file:///nodes.csv" as persons FIELDTERMINATOR ';' return persons.`label`;
于 2017-08-17T17:33:44.280 回答
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"}  │
└───────────────────────────────────────────────┘
于 2017-08-17T16:16:37.947 回答