I am trying to create 500,000 nodes in a graph database. I plan to add edges as per my requirements later. I have a text file with 500,000 lines representing the data to be stored in each node.
from bulbs.neo4jserver import Graph, Config, NEO4J_URI
config = Config(NEO4J_URI)
g = Graph(config)
def get_or_create_node(text, crsqid):
v = g.vertices.index.lookup(crsqid=crsqid)
if v==None:
v = g.vertices.create(crsqid=crsqid)
print text + " - node created"
v.text = text
v.save()
return v
I then loop over each line in the text file,
count = 1
with open('titles-sorted.txt') as f:
for line in f:
get_or_create_node(line, count)
count += 1
This is terribly slow. This gives me 5000 nodes in 10 minutes. Can this be improved? Thanks