使用与该节点之间的关系数更新我的所有节点属性

Update all of my node properties with both the number of relationships to and from that node

所以我在想一些单独的事情:

MATCH (a:Entity)<--(x:Entity) SET a.links_to=count(x) MATCH (a:Entity)-->(x:Entity) SET a.links_from=计数(x)

我怎样才能在 Cypher 中正确地写这个? 我怎样才能以快速且最好是并行的方式执行此操作,也许是通过使用 Apoc?

这是一个昂贵的操作,但如果你想这样做,这里是它的密码查询:

match (a)-[]->(b) 
with a, b, 
CASE WHEN exists(a.outgoingEdges) THEN a.outgoingEdges+1 else 1 END as outgoingEdges,
CASE WHEN exists(b.incomingEdges) THEN b.incomingEdges+1 else 1 END as incomingEdges
SET
 a.outgoingEdges= outgoingEdges,
 b.incomingEdges = incomingEdges

这可以非常有效地完成。

Match (e:Entity)
Set e.links_to = size((e)<--()),
      e.links_from = size((e)-->())

如果你想使用 APOC 加速并运行并行

Call apoc.periodic.iterate(
' match (e:Entity) return e',
' set e.links_to = size((e)<--()),
      e.links_from = size((e)-->())',
{batchSize:10000,parallel: true})

很好的回应。 Apoc 解决方案效果特别好。非常感谢!