简体   繁体   English

在Neo4j中从双向关系查询单个关系

[英]Querying single relationship from a bidirectional relationship in Neo4j

重叠双向关系

Is it possible to show only one direction relationship from a bidirectional relationship? 是否可能仅显示双向关系中的一个方向关系?

(n)-[:EMAIL_LINK]->(m) (N) - [:EMAIL_LINK] - >(M)

(n)<-[:EMAIL_LINK]-(m) (N)< - [:EMAIL_LINK] - (M)

If the relationship type in question does not have directional semantics, it's best practice to have them only one time in the graph and omit the direction while querying, ie (a)-[:EMAIL_LINK]-(b) instead of (a)-[:EMAIL_LINK]->(b) . 如果所讨论的关系类型不具有方向性语义,则最佳做法是在图表中仅使用一次,并在查询时忽略方向,即(a)-[:EMAIL_LINK]-(b)而不是(a)-[:EMAIL_LINK]->(b)

To get rid of duplicated relationships in different directions, use: 要摆脱不同方向上的重复关系,请使用:

MATCH (a)-[r1:EMAIL_LINK]->(b)<-[r2:EMAIL_LINK]-(a)
WHERE ID(a)<ID(b)
DELETE r2

if your graph is large you need to take care of having reasonable transaction sizes by adding a LIMIT and running the query multiple times until all have been processed. 如果您的图形很大,则需要通过添加LIMIT并多次运行查询直到所有处理都完成,来确保事务大小合理。

NB: the WHERE ID(a)<ID(b) is necessary. 注意: WHERE ID(a)<ID(b)是必需的。 Otherwise a and b might change roles during in a later iteration. 否则, ab可能会在以后的迭代中更改角色。 Consequently r1 and r2 would change roles as well and both get deleted. 因此, r1r2也将更改角色,并且都将被删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM