Trying to insert many new Relationship on existing nodes. Current code is taking too much time for millions of Relationship. Is there a way to optimise the same?
from py2neo import *
g = Graph()
nodes = NodeMatcher(g)
for persons in relation:
person_a, person_b = persons
a = nodes.match("person",name=person_a).first()
b = nodes.match("person",name=person_b).first()
ab = Relationship(a, 'KNOWS' b)
ab['date'] = '01-01-1980'
g.create(ab)
Now assume 2 things:
- Relations are in millions
- To process things faster, I have a pickle dump which consists of all the node details in
py2neo.data.Node
datatype so that we can skip thenodes.match(...)
part.
Note: If there is any other way to create the complete graph faster in bulk mode (where I'm willing to create the entire graph from scratch if time taken by adding Relationships > time taken to create entire graph). Number of nodes are around 80K.