我正在尝试将包含节点(+200000)的CSV和它们之间的边缘导入到Neo4J中。
1)由于某些原因我无法找到,当文件大小超过5000行(或左右)时,根本不会创建关系。
USING PERIODIC COMMIT 100
LOAD CSV WITH HEADERS FROM "file:///export_conceptos_50000.txt" AS csvLine
FIELDTERMINATOR '\t'
MERGE (c:Concepto {nom: csvLine.concepto1_sin, cat: csvLine.c1cat})
MERGE (d:Concepto {nom: csvLine.concepto2_sin, cat: csvLine.c2cat})
FOREACH(ignoreMe IN CASE WHEN csvLine.relacion='Is_a' THEN [1] ELSE [] END | MERGE (c)-[:Is_a]->(d) )
FOREACH(ignoreMe IN CASE WHEN csvLine.relacion='Finding_site' THEN [1] ELSE [] END | MERGE (c)-[:Finding_site]->(d) )
所以这个是原始问题:不会创建边缘。
2)作为替代方案,我尝试将文件拆分为较小的文件,然后通过neo4j-shell(Neo4J Linux shell实用程序)导入。
这是命令行:
./neo4j-shell -file /usr/share/neo4j/scripts/query.cypher -path /usr/share/neo4j/neo4j-community-3.1.1/data/databases/graph.db
这是输出:
ERROR (-v for expanded information):
Error starting org.neo4j.kernel.impl.factory.GraphDatabaseFacadeFactory, /usr/share/neo4j/neo4j-community-3.1.1/data/databases/graph.db
我猜是因为已经有Neo4J引擎在运行。
然后,我应该如何在命令行指定目标数据库?
谢谢!
答案 0 :(得分:1)
您可能希望进行多次传递,否则您可能会因急切加载CSV数据而遇到问题
也许你的条件有问题,如果你做了多遍,你也可以把它们改成一个简单的WHERE
USING PERIODIC COMMIT 100000
LOAD CSV WITH HEADERS FROM "file:///export_conceptos_50000.txt" AS csvLine
FIELDTERMINATOR '\t'
MERGE (c:Concepto {nom: csvLine.concepto1_sin, cat: csvLine.c1cat});
USING PERIODIC COMMIT 100000
LOAD CSV WITH HEADERS FROM "file:///export_conceptos_50000.txt" AS csvLine
FIELDTERMINATOR '\t'
MERGE (d:Concepto {nom: csvLine.concepto2_sin, cat: csvLine.c2cat});
USING PERIODIC COMMIT 10000
LOAD CSV WITH HEADERS FROM "file:///export_conceptos_50000.txt" AS csvLine
FIELDTERMINATOR '\t'
WITH csvLine WHERE csvLine.relacion='Is_a'
MATCH (c:Concepto {nom: csvLine.concepto1_sin, cat: csvLine.c1cat})
MATCH (d:Concepto {nom: csvLine.concepto2_sin, cat: csvLine.c2cat})
MERGE (c)-[:Is_a]->(d);
USING PERIODIC COMMIT 10000
LOAD CSV WITH HEADERS FROM "file:///export_conceptos_50000.txt" AS csvLine
FIELDTERMINATOR '\t'
WITH csvLine WHERE csvLine.relacion='Finding_site'
MATCH (c:Concepto {nom: csvLine.concepto1_sin, cat: csvLine.c1cat})
MATCH (d:Concepto {nom: csvLine.concepto2_sin, cat: csvLine.c2cat})
MERGE (c)-[:Finding_site]->(d);