简体   繁体   English

从CSV导入数据到Neo4J

[英]Importing data into Neo4J from CSV

I am trying to import a CSV containing nodes (+200000) and edges between them, into Neo4J. 我正在尝试将包含节点(+200000)和它们之间的边缘的CSV导入Neo4J。

1) For some reason that I could not find out, when the file size is over 5000 lines (or so), relationships do not get created at all. 1)由于某种原因,我无法找出文件大小超过5000行(或大约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) )

So this is the original issue: edges are not created. 所以是原始问题:不创建边。

2) As an alternative, I tried to split the file into smaller ones, and then import via neo4j-shell (Neo4J Linux shell utility). 2)作为替代,我尝试将文件拆分为较小的文件,然后通过neo4j-shell(Neo4J Linux Shell实用程序)导入。

This is the command line: 这是命令行:

./neo4j-shell -file /usr/share/neo4j/scripts/query.cypher -path /usr/share/neo4j/neo4j-community-3.1.1/data/databases/graph.db

and this is the output: 这是输出:

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

which I guess is due to the fact that there is already a Neo4J engine running. 我猜这是由于已经有Neo4J引擎在运行。

Then, how should I specify the target database at the command line? 然后,如何在命令行中指定目标数据库?

Thanks! 谢谢!

  1. you might want to do multi-pass, as otherwise you might get problems with eager loading of your CSV data 您可能需要进行多次扫描,否则可能会导致急于加载CSV数据时出现问题

  2. perhaps there is something wrong in your conditionals, if you do multi-pass anyway you can also change them to a simple WHERE 可能您的条件句中有问题,如果您仍然进行多遍操作,也可以将其更改为简单的WHERE

like this: 像这样:

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);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM