簡體   English   中英

如何使用cypher從neo4j中的不同文件加載節點和邊?

[英]How do I load nodes and edges from different files in neo4j using cypher efficiently?

假設我有一個包含節點信息的csv文件,每行具有唯一的id(第一列),另一個csv文件包含邊緣,它們描述了節點之間的邊緣(通過其唯一ID)。 以下密碼代碼成功加載了節點,然后創建了邊。 但是,我可以提高效率嗎? 我的真實數據集具有數百萬個節點和數千萬條邊。 顯然,我應該使用定期提交並創建索引,但是我可以以某種方式避免對每個單個邊緣進行match ,並利用我知道要構建的每個邊緣的唯一節點ID的事實嗎? 還是我要解決所有這些錯誤? 我想完全在cypher(沒有java)中做到這一點。

load csv from 'file:///home/user/nodes.txt' as line
create (:foo { id: toInt(line[0]), name: line[1], someprop: line[2]});

load csv from 'file:///home/user/edges.txt' as line
match (n1:foo { id: toInt(line[0])} ) 
with n1, line
match (n2:foo { id: toInt(line[1])} ) 
// if I had an index I'd use it here with: using index n2:foo(name) 
merge (n1) -[:bar]-> (n2) ;

match p = (n)-->(m) return p;

nodes.txt

0,node0,Some Property 0
1,node1,Some Property 1
2,node2,Some Property 2
3,node3,Some Property 3
4,node4,Some Property 4
5,node5,Some Property 5
6,node6,Some Property 6
7,node7,Some Property 7
8,node8,Some Property 8
9,node9,Some Property 9
10,node10,Some Property 10
...

edges.txt

0,2
0,4
0,8
0,13
1,4
1,8
1,15
2,4
2,6
3,4
3,7
3,8
3,11
4,10
...

就像Ron上面評論的那樣,對於大型數據集,LOAD CSV可能不是可行的方法,他鏈接到的csv Batch Import工具也很棒。 如果您發現無法以與批處理導入工具一起使用的方式輕松插入csv,則Neo4J BatchInserter API的使用非常簡單: http ://docs.neo4j.org/chunked/stable/batchinsert.html

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM