简体   繁体   English

使用Cypher在Neo4j中创建多个节点

[英]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. 这是Cypher中Neo4j的常规创建语法。

I have 4038 such nodes. 我有4038个这样的节点。

Neo4j supposedly accepts one query at a time. Neo4j应该一次接受一个查询。 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. 另外,我还有另一个定义关系的文件,其数量约为200000。 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 : 您可以使用WITH传递一个虚拟变量,以便一次执行多个查询:

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? 您可以检查此示例以获取更多信息: 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. 您要做的就是在每个请求之间WITH 1 as dummy C / P WITH 1 as dummy ,那么您就有一个大请求。

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

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