Neo4j create multiple nodes and relationships

cypher, neo4j

Solution

Two alternatives I'd consider:

- Use the `LOAD CSV` support: http://docs.neo4j.org/chunked/stable/query-load-csv.html

- Use a single paramaterized Cypher statement, and supply an array of parameters: http://docs.neo4j.org/chunked/stable/query-create.html#create-create-multiple-nodes-with-a-parameter-for-their-properties

Otherwise there is the batch inserter, as mentioned.

Problem

I am using Neo4j to build a huge graph database (over a million nodes). The way I'm doing it right now is running a cypher `CREATE (n {property:'value'})` query for each of the node. As expected, this is quite an inefficient method and it takes lots of time. Can somebody suggest me some alternative method to overcome this issue? I've heard that Neo4j also provides some default batch interface to create multiple nodes. I'm currently using this version of code (including the relationship): `create (a { name: "a" })-[:rel1]->(b {name : "b"}),(c {name: "c"})-[:rel2]->(d {name:"d"}),...` Is it an efficient method or are there any better methods? Thanks in advance! :)

Original source