【问题标题】:Update all of my node properties with both the number of relationships to and from that node使用与该节点的关系数更新我的所有节点属性
【发布时间】:2019-01-05 15:19:43
【问题描述】:

所以我在想一些单独的东西:

MATCH (a:Entity)(x:Entity) SET a.links_from=count(x)

我怎样才能在 Cypher 中正确地写这个? 我怎样才能以一种快速且最好是并行的方式做到这一点,也许是通过使用 Apoc ?

【问题讨论】:

  • :实体节点是唯一连接到其他:实体的节点吗?如果是这样,那么根本不需要这样做,因为关系度数据已经在节点本身上,您只需要在查询中查找即可。如果是这种情况,请告诉我,我将添加如何执行此操作作为答案。

标签: neo4j count cypher relationship store


【解决方案1】:

这可以非常有效地完成。

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})

【讨论】:

    【解决方案2】:

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

    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
    

    【讨论】:

      【解决方案3】:

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

      【讨论】:

      • 您可以投票并将答案设置为正确,这是您的答案
      猜你喜欢
      • 2017-05-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多