Reputation: 123
I have made a simple java code to make relations among more than 600 thousand existing nodes, the relation data is taken from 1 million rows, the problem is it takes almost forever to finish creating relations, only 7930 relations are created at the moment of writing this post.
How this problem could be solved?
public void createRealtionBetweenNodes(Postgresql object){
Map<Integer, String[][]> data = object.getRelationData();
try (Driver driver = org.neo4j.driver.v1.GraphDatabase.driver( "bolt://localhost:7687", AuthTokens.basic( "user", "password" ) );
Session session = driver.session()){
for(int incrementer: data.keySet()){
String [][] dataholder = data.get(incrementer);
session.run( "match (x:Node{id:{id1}}),(y:Node{id:{id2}}) create (x)-[:Knows{ID:{KID}}]->(y);", parameters("id1",dataholder[0][0],"id2",dataholder[0][1],"KID",dataholder[0][2]));
}
}
}
Upvotes: 0
Views: 143
Reputation: 41676
You should also not create a Driver and Session per insert. But rather keep them and create a transaction per 10k to 100k relationships.
Also to speed this up further, have a look here: http://jexp.de/blog/2017/03/5-tips-tricks-for-fast-batched-updates-of-graph-structures-with-neo4j-and-cypher/
Upvotes: 1
Reputation: 767
I would guess,based on the data you provide, that Node.id is not indexed. If it's not, and there are a lot of Node nodes, database hits could be a lot until it matches the id. Try creating an index and running this again.
Upvotes: 3