今天在用Neo4j的时候出现了下面的错误:
➜ installation-3.5.6 ./bin/neo4j-admin import --mode=csv --database=graph.db --nodes /Users/admin/Documents/data/knowledgeGraph/students.csv,/Users/admin/Documents/data/knowledgeGraph/classes.csv --relationships /Users/admin/Documents/data/knowledgeGraph/relations.csv
Neo4j version: 3.5.6
Importing the contents of these files into /Users/admin/Library/Application Support/Neo4j Desktop/Application/neo4jDatabases/database-42c2a528-01e9-4145-99ad-da0123d20d59/installation-3.5.6/data/databases/graph.db:
Nodes:
/Users/admin/Documents/data/knowledgeGraph/students.csv
/Users/admin/Documents/data/knowledgeGraph/classes.csv
Relationships:
/Users/admin/Documents/data/knowledgeGraph/relations.csv
Available resources:
Total machine memory: 16.00 GB
Free machine memory: 194.43 MB
Max heap memory : 910.50 MB
Processors: 8
Configured max memory: 13.60 GB
High-IO: true
WARNING: 122.18 MB memory may not be sufficient to complete this import. Suggested memory distribution is:
heap size: 1.00 GB
minimum free and available memory excluding heap size: 1020.01 MBImport starting 2019-07-30 19:15:47.680+0800
Estimated number of nodes: 11.00
Estimated number of node properties: 22.00
Estimated number of relationships: 6.00
Estimated number of relationship properties: 0.00
Estimated disk space usage: 831.00 B
Estimated required memory usage: 1020.01 MB
InteractiveReporterInteractions command list (end with ENTER):
c: Print more detailed information about current stage
i: Print more detailed information
(1/4) Node import 2019-07-30 19:15:47.715+0800
Estimated number of nodes: 11.00
Estimated disk space usage: 627.00 B
Estimated required memory usage: 1020.01 MB
.......... .......... .......... .......... .......... 5% ∆61ms
.......... .......... .......... .......... .......... 10% ∆2ms
.......... .......... .......... .......... .......... 15% ∆0ms
.......... .......... .......... .......... .......... 20% ∆1ms
.......... .......... .......... .......... .......... 25% ∆0ms
.......... .......... .......... .......... .......... 30% ∆1ms
.......... .......... .......... .......... .......... 35% ∆0ms
.......... .......... .......... .......... .......... 40% ∆1ms
.......... .......... .......... .......... .......... 45% ∆0ms
.......... .......... .......... .......... .......... 50% ∆1ms
.......... .......... .......... .......... .......... 55% ∆1ms
.......... .......... .......... .......... .......... 60% ∆0ms
.......... .......... .......... .......... .......... 65% ∆1ms
.......... .......... .......... .......... .......... 70% ∆1ms
.......... .......... .......... .......... .......... 75% ∆0ms
.......... .......... .......... .......... .......... 80% ∆1ms
.......... .......... .......... .......... .......... 85% ∆0ms
.......... .......... .......... .......... .......... 90% ∆1ms
.......... .......... .......... .......... .......... 95% ∆0ms
.......... .......... .......... .......... .......... 100% ∆0ms
IMPORT FAILED in 262ms.
Data statistics is not available.
Peak memory usage: 0.00 B
Error in input data
Caused by:ERROR in input
data source: BufferedCharSeeker[source:/Users/admin/Documents/data/knowledgeGraph/classes.csv, position:34, line:1]
in field: :LABEL:4
for header: [classId:ID, name:string, :LABEL]
raw field value: :LABEL
original error: Extra column not present in header on line 1 in /Users/admin/Documents/data/knowledgeGraph/classes.csv with value :LABEL
WARNING Import failed. The store files in /Users/admin/Library/Application Support/Neo4j Desktop/Application/neo4jDatabases/database-42c2a528-01e9-4145-99ad-da0123d20d59/installation-3.5.6/data/databases/graph.db are left as they are, although they are likely in an unusable state. Starting a database on these store files will likely fail or observe inconsistent records so start at your own risk or delete the store manually
unexpected error: ERROR in input
data source: BufferedCharSeeker[source:/Users/admin/Documents/data/knowledgeGraph/classes.csv, position:34, line:1]
in field: :LABEL:4
for header: [classId:ID, name:string, :LABEL]
raw field value: :LABEL
original error: Extra column not present in header on line 1 in /Users/admin/Documents/data/knowledgeGraph/classes.csv with value :LABEL
我的文件为class.csv:
studentId:ID,name,age:int,:LABEL
s1,"JM68",27,Student
s2,"JM6",22,Student
s3,"JM8",18,Student
s4,"JM",2,Student
students.csv:
classId:ID,name,:LABEL
c1,"MHT班",Class
c2,"MY班",Class
c3,"LYH班",Class
c4,"RZF班",Class
relations.csv:
:START_ID,:END_ID,:TYPE
s1,c4,FROM
s2,c2,FROM
s3,c3,FROM
s4,c1,FROM
然后我运行的命令为:
./bin/neo4j-admin import --mode=csv --database=graph.db --nodes
/Users/admin/Documents/data/knowledgeGraph/students.csv,
/Users/admin/Documents/data/knowledgeGraph/classes.csv
--relationships /Users/admin/Documents/data/knowledgeGraph/relations.csv
解决方法
./bin/neo4j-admin import --mode=csv --database=graph.db
--nodes /Users/admin/Documents/data/knowledgeGraph/students.csv
--nodes /Users/admin/Documents/data/knowledgeGraph/classes.csv
--relationships /Users/admin/Documents/data/knowledgeGraph/relations.csv
原因是我只写了一个 nodes参数,然后读取了两个文件,neo4j以为格式都是一样的。最后分开读nodes文件就行了。
参考文献
[1]. 使用 官方 etl neo4j-import 导入 数据. http://weikeqin.com/2017/04/11/neo4j-import/
[2]. Neo4j--数据导入. https://www.jianshu.com/p/e968c5ccf34c