您可以使用批处理加载程序执行此操作,但使用 Gremlin 脚本会更容易。
如果您nodelist
是节点 ID 对的列表,这里是 Gremlin 脚本批量加载边缘(未经测试)...
// gremlin.groovy
def batch_load(nodelist, label) {
g.setMaxBufferSize(0)
g.startTransaction()
try {
for (entry in nodelist) {
s_id = entry[0]
d_id = entry[1]
// if s_id and d_id are actual node IDs, you don't need to use an index...
sn = g.idx('someindex').get('nid',s_id)[0]
dn = g.idx('someindex').get('nid',d_id)[0]
g.addEdge(sn,dn,label)
}
g.stopTransaction(TransactionalGraph.Conclusion.SUCCESS)
return true
} catch (e) {
g.stopTransaction(TransactionalGraph.Conclusion.FAILURE)
return e
}
}
以下是您在 Bulbs 中执行它的方式——您需要为 neo4jrestclient 修改它...
>>> from bulbs.neoj4server import Graph
>>> g = Graph()
>>> g.scripts.update('/path/to/gremlin.groovy')
>>> script = g.scripts.get('batch_load')
>>> params = dict(nodelist=your_node_list, label="follows")
>>> g.gremlin.execute(script, params)