title: Neo4j, bulk load with Cypher commands
body: <p>I'm new to Neo4j and there must be something I don't understand about the basics.</p>
  
  <p>I've many objects in Java and I want to use them to populate a Neo4j graph, using the Java driver and Cypher. My code works like this:</p>
  
  <pre><code>// nodes
  for ( Person person: persons )
    session.run ( String.format ( 
      "CREATE ( :Person { id: '%s', name: \"%s\", surname: \"%s\" })",
      person.getId(), person.getName(), person.getSurname ()
    ));
  
  // relations
  session.run ( "CREATE INDEX ON :Person(id)" );
  
  for ( Friendship friendship: friendships )
    session.run ( String.format ( 
      "MATCH ( from:Person { id: '%s' } ), ( to:Person { id: '%s' } )\n" +
      "CREATE (from)-:KNOWS-&gt;(to)\n",
      friendship.getFrom().getId(), 
      friendship.getTo().getId() 
    )); 
  </code></pre>
  
  <p>(indeed, it's slightly more complicated, cause I have a dozen node types and about the same number of relation types).</p>
  
  <p>Now, this is very slow, like more than 1 hour to load 300k nodes and 1M relations (on a fairly fast MacBookPro, with Neo4j taking 12/16GB of RAM).</p>
  
  <p>Am I doing it the wrong way? Should I use the <a href="http://neo4j.com/docs/stable/batchinsert-examples.html" rel="nofollow noreferrer">batch inserter</a> instead? (I would prefer to be able to access the graphDB via network). Would I gain something by grouping more insertions into one transaction? (From the documentation, It seems transactions are only useful for rolling back and for isolation needs).</p>