I'm new to Neo4j and there must be something I don't understand about the basics.
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:
// 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->(to)\n",
friendship.getFrom().getId(),
friendship.getTo().getId()
));
(indeed, it's slightly more complicated, cause I have a dozen node types and about the same number of relation types).
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).
Am I doing it the wrong way? Should I use the batch inserter 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).