2016-07-08 82 views
0

我有以下格式的密碼查詢的文本文件。使用Cypher在Neo4j中創建多個節點

create(n:`0`{`78`:78, `127`:127, `336`:336, `346`:346, `349`:349, `55`:55, `255`:255, `61`:61, `354`:354, `356`:356, `97`:97, `361`:361, `338`:338, `217`:217, `348`:348, `53`:53, `61`:61, `92`:92, `3`:3, `210`:210, `54`:54, `352`:352, `354`:354, `209`:209, `3`:3, `210`:210, `345`:345, `72`:72, `360`:360, `361`:361, `209`:209, `340`:340, `72`:72, `352`:352, `359`:359, `97`:97, `2`:2, `344`:344, `345`:345, `255`:255, `65`:65, `67`:67, `77`:77, `344`:344, `350`:350, `92`:92, `338`:338, `337`:337, `340`:340, `55`:55, `97`:97, `14`:14, `342`:342, `255`:255, `356`:356, `357`:357, `77`:77, `335`:335, `344`:344, `351`:351, `355`:355, `360`:360, `337`:337, `348`:348, `77`:77, `3`:3, `53`:53, `352`:352, `97`:97, `209`:209, `14`:14, `338`:338, `347`:347, `348`:348, `354`:354, `209`:209, `14`:14, `338`:338, `3`:3, `343`:343, `255`:255, `354`:354, `97`:97, `360`:360, `341`:341, `72`:72, `92`:92, `338`:338, `347`:347, `61`:61, `64`:64, `65`:65, `352`:352, `353`:353, `354`:354, `355`:355, `361`:361, `2`:2, `340`:340, `343`:343, `351`:351, `355`:355, `209`:209, `335`:335, `338`:338, `339`:339, `346`:346, `348`:348, `64`:64, `71`:71, `77`:77, `78`:78, `351`:351, `72`:72, `359`:359, `337`:337, `217`:217, `53`:53, `55`:55, `351`:351, `355`:355, `356`:356, `77`:77, `217`:217, `339`:339, `348`:348, `349`:349, `53`:53, `351`:351, `67`:67, `357`:357, `77`:77, `3`:3, `335`:335, `351`:351, `352`:352, `336`:336, `347`:347, `348`:348, `55`:55, `350`:350, `255`:255, `359`:359, `209`:209, `2`:2, `53`:53, `54`:54, `72`:72, `353`:353, `2`:2, `14`:14, `342`:342, `344`:344, `255`:255, `354`:354, `355`:355, `77`:77, `97`:97, `360`:360, `361`:361, `209`:209, `336`:336, `345`:345, `348`:348, `349`:349, `65`:65, `2`:2, `3`:3, `340`:340, `342`:342, `71`:71, `72`:72, `92`:92, `97`:97, `337`:337, `347`:347, `64`:64, `65`:65, `357`:357, `360`:360, `339`:339, `342`:342, `351`:351, `361`:361, `337`:337, `342`:342, `64`:64, `358`:358, `2`:2, `342`:342, `346`:346, `348`:348, `54`:54, `350`:350, `61`:61, `64`:64, `359`:359, `92`:92, `97`:97, `360`:360, `336`:336, `341`:341, `217`:217, `53`:53, `350`:350, `353`:353, `347`:347, `349`:349, `357`:357, `3`:3, `210`:210, `336`:336, `346`:346, `349`:349, `355`:355, `356`:356, `358`:358, `353`:353, `360`:360, `348`:348, `65`:65, `71`:71, `2`:2, `341`:341, `344`:344, `350`:350, `352`:352, `353`:353, `92`:92, `360`:360, `345`:345, `64`:64, `65`:65, `2`:2, `340`:340, `341`:341, `67`:67, `359`:359, `336`:336, `345`:345, `351`:351, `255`:255, `61`:61, `217`:217, `339`:339, `55`:55, `14`:14, `61`:61, `355`:355, `357`:357, `336`:336, `340`:340, `342`:342, `354`:354, `337`:337, `348`:348, `71`:71, `97`:97, `3`:3, `217`:217, `55`:55, `350`:350, `351`:351, `352`:352}); 


create(n:`1`{`77`:77, `127`:127, `337`:337, `338`:338, `346`:346, `348`:348, `356`:356, `209`:209, `335`:335, `337`:337, `348`:348, `53`:53, `67`:67, `335`:335, `346`:346, `67`:67, `77`:77, `53`:53, `67`:67, `2`:2, `339`:339, `346`:346, `348`:348, `53`:53, `55`:55, `71`:71, `353`:353}); 


create(n:`2`{`35`:35, `53`:53, `55`:55, `57`:57, `78`:78, `92`:92, `98`:98, `114`:114, `126`:126, `135`:135}); 


create(n:`3`{`7`:7, `14`:14, `34`:34, `50`:50, `53`:53, `55`:55, `59`:59, `65`:65, `78`:78, `92`:92, `127`:127, `137`:137, `168`:168, `170`:170, 
`137`:137, `164`:164, `202`:202}); 


create(n:`4`{`50`:50, `53`:53, `55`:55, `56`:56, `78`:78, `127`:127}); 

等等。 這是Cypher中Neo4j的正常創建語法。

我有4038個這樣的節點。

Neo4j據說一次接受一個查詢。一次複製並粘貼一個查詢的效率非常低。

此外,我還有另一個文件定義的關係,這是約200000的數量。一次複製和粘貼一個查詢是完全不切實際的。

我需要一些幫助來自動化過程。

回答

1

則可以使用帶能夠在同一時間做多個查詢通過一個虛擬變量:

create(n:`0`{`78`:78, `127`:127, `336`:336, `346`:346, `349`:349, `55`:55, `255`:255, `61`:61, `354`:354, `356`:356, `97`:97, `361`:361, `338`:338, `217`:217, `348`:348, `53`:53, `61`:61, `92`:92, `3`:3, `210`:210, `54`:54, `352`:352, `354`:354, `209`:209, `3`:3, `210`:210, `345`:345, `72`:72, `360`:360, `361`:361, `209`:209, `340`:340, `72`:72, `352`:352, `359`:359, `97`:97, `2`:2, `344`:344, `345`:345, `255`:255, `65`:65, `67`:67, `77`:77, `344`:344, `350`:350, `92`:92, `338`:338, `337`:337, `340`:340, `55`:55, `97`:97, `14`:14, `342`:342, `255`:255, `356`:356, `357`:357, `77`:77, `335`:335, `344`:344, `351`:351, `355`:355, `360`:360, `337`:337, `348`:348, `77`:77, `3`:3, `53`:53, `352`:352, `97`:97, `209`:209, `14`:14, `338`:338, `347`:347, `348`:348, `354`:354, `209`:209, `14`:14, `338`:338, `3`:3, `343`:343, `255`:255, `354`:354, `97`:97, `360`:360, `341`:341, `72`:72, `92`:92, `338`:338, `347`:347, `61`:61, `64`:64, `65`:65, `352`:352, `353`:353, `354`:354, `355`:355, `361`:361, `2`:2, `340`:340, `343`:343, `351`:351, `355`:355, `209`:209, `335`:335, `338`:338, `339`:339, `346`:346, `348`:348, `64`:64, `71`:71, `77`:77, `78`:78, `351`:351, `72`:72, `359`:359, `337`:337, `217`:217, `53`:53, `55`:55, `351`:351, `355`:355, `356`:356, `77`:77, `217`:217, `339`:339, `348`:348, `349`:349, `53`:53, `351`:351, `67`:67, `357`:357, `77`:77, `3`:3, `335`:335, `351`:351, `352`:352, `336`:336, `347`:347, `348`:348, `55`:55, `350`:350, `255`:255, `359`:359, `209`:209, `2`:2, `53`:53, `54`:54, `72`:72, `353`:353, `2`:2, `14`:14, `342`:342, `344`:344, `255`:255, `354`:354, `355`:355, `77`:77, `97`:97, `360`:360, `361`:361, `209`:209, `336`:336, `345`:345, `348`:348, `349`:349, `65`:65, `2`:2, `3`:3, `340`:340, `342`:342, `71`:71, `72`:72, `92`:92, `97`:97, `337`:337, `347`:347, `64`:64, `65`:65, `357`:357, `360`:360, `339`:339, `342`:342, `351`:351, `361`:361, `337`:337, `342`:342, `64`:64, `358`:358, `2`:2, `342`:342, `346`:346, `348`:348, `54`:54, `350`:350, `61`:61, `64`:64, `359`:359, `92`:92, `97`:97, `360`:360, `336`:336, `341`:341, `217`:217, `53`:53, `350`:350, `353`:353, `347`:347, `349`:349, `357`:357, `3`:3, `210`:210, `336`:336, `346`:346, `349`:349, `355`:355, `356`:356, `358`:358, `353`:353, `360`:360, `348`:348, `65`:65, `71`:71, `2`:2, `341`:341, `344`:344, `350`:350, `352`:352, `353`:353, `92`:92, `360`:360, `345`:345, `64`:64, `65`:65, `2`:2, `340`:340, `341`:341, `67`:67, `359`:359, `336`:336, `345`:345, `351`:351, `255`:255, `61`:61, `217`:217, `339`:339, `55`:55, `14`:14, `61`:61, `355`:355, `357`:357, `336`:336, `340`:340, `342`:342, `354`:354, `337`:337, `348`:348, `71`:71, `97`:97, `3`:3, `217`:217, `55`:55, `350`:350, `351`:351, `352`:352}) 

WITH 1 as whatever 

create(n:`1`{`77`:77, `127`:127, `337`:337, `338`:338, `346`:346, `348`:348, `356`:356, `209`:209, `335`:335, `337`:337, `348`:348, `53`:53, `67`:67, `335`:335, `346`:346, `67`:67, `77`:77, `53`:53, `67`:67, `2`:2, `339`:339, `346`:346, `348`:348, `53`:53, `55`:55, `71`:71, `353`:353}) 

等等...

您可以檢查更多的信息這個例子:Multiple unrelated queries in Neo4j Cypher?

所有你需要做的是每個你的請求之間的C/P WITH 1 as dummy,然後你有一個大的請求。

+0

嘗試這給了我一個錯誤,「每個查詢只需要一個語句,但得到:4040」 –

+0

oh nvm,您還必須在創建語句結束時刪除';'。我修正了這個例子。 – Supamiu

+0

是的,謝謝你,工作。但是,它適用於小型數據庫。當我一起輸入所有4038個查詢時,它運行了一段時間,並給了我錯誤「Neo.DatabaseError.General.UnknownError」。 –

相關問題