简体   繁体   中英

Creation of multiple nodes in Neo4j using Cypher

I have a text file of cypher queries in the following format.

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

and so on. This is a normal create syntax for Neo4j in Cypher.

I have 4038 such nodes.

Neo4j supposedly accepts one query at a time. Copying and pasting one query at a time is quite inefficient.

Also I have another file defining the relationships, which is around a 200000 in number. It is completely impractical to copy and paste one query at a time.

I need some help to automate the process.

You can pass a dummy variable using WITH to be able to do multiple queries at one time :

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

and so on...

You can check this example for more informations: Multiple unrelated queries in Neo4j Cypher?

All you have to do is C/P WITH 1 as dummy between each one of your request, then you have one big request.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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