cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to create multiple nodes with a cypher script?

jzhou002
Node Link

I created a nested json file that contains >10K nodes, each node has >150 properties, I successfully loaded it into neo4j (4.3.1), but, of course, nodes were not created. I know that I can use "CREATE/MERGE (n:PROPERTY) [ON CREATE] SET " method, but for the amount of sample data I have I need type 10K*150 times to "SET n.p1 = xxx, n.p2=xxx.....". I used java to create a cypher script to do that, but the result was that only the first node was created. So I hope some one can provide a sample cypher script file that can create multiple nodes and set properties.
Thanks.

3 REPLIES 3

jzhou002
Node Link

The cypher script I created look like this:
begin
MERGE (n:PROPERTY) ON CREATE set
n.p1 = xxxx,
n.p2 = xxxx,
.......,
n.p155 = xxxx ;
commit

begin
MERGE (n:PROPERTY) ON CREATE set
n.p1 = xxxx,
n.p2 = xxxx,
.......
n.p155 = xxxx;
commit

the nodes creation repeats to the end of the cypher script.
This is the first time I tried to create nodes in a cypher script, I copied the format from internet search, but not sure that is correct format. So I need a sample, hope some one can provide a working sample. Thanks.

jzhou002
Node Link

I solved my issue I posted above, but I have a new issue, I ran the cypher script twice, the first time it creates nodes, the second time it stops at first node creation, that is expected because the node has been created, so the error is "Node (0) already exists with label xxxxxx". Is it possible to skip this error. I may add more nodes creation to the cypher script file in the future, so I hope that repeatedly running the same script skips the creation of nodes that exist, only creates nodes that do not exist. Thanks.

Again I solved my question myself. If I need to add new node creations to the script, I add at the beginning of the cypher script.