[英]Relationship count in neo4j
I have a question. 我有个问题。 I am trying to run this query.
我正在尝试运行此查询。
START n= NODE(5749,5750,5751,5752,5753,5754,5755,5756,5757,5758,5759,5760)
MATCH p=(a)-[:KNOWS]-(n)-[:KNOWS]-(b)
OPTIONAL MATCH q=(a)-[:KNOWS]-(b)
RETURN Distinct n.name AS ID,COUNT(distinct p) as NR, COUNT(q) as BR;
The results are bit weird. 结果有点奇怪。 My DB has
276597
nodes and 401634
relationships in total. 我的数据库总共有
276597
节点和401634
关系。 But in the result of the above query I have 392502
relationships for one node in graphical view. 但是在上述查询的结果中,我在图形视图中具有一个节点的
392502
关系。 I found 2 q relationships
but in tabular form they are zero! 我发现2个
q relationships
但以表格形式它们是零!
Here are the results of the above query: 以下是上述查询的结果:
Since you did not indicate the directionality of any relationships in your query, your counts include duplicates (notice that all your results are even numbers). 由于您没有在查询中指出任何关系的方向性,因此您的计数包括重复项(请注意,所有结果均为偶数)。
This slightly modified version of your query should get better results (you should use whatever directionality applies to your use case): 这个稍作修改的查询版本应该会获得更好的结果(您应该使用适用于您的用例的任何方向性):
START n= NODE(5749,5750,5751,5752,5753,5754,5755,5756,5757,5758,5759,5760)
MATCH p=(a)-[:KNOWS]->(n)-[:KNOWS]->(b)
OPTIONAL MATCH q=(a)-[:KNOWS]-(b)
RETURN Distinct n.name AS ID,COUNT(distinct p) as NR, COUNT(q) as BR;
The OPTIONAL MATCH
clause still does not specify any directionality, since I presumed that you really wanted to get both directions in that case. OPTIONAL MATCH
子句仍然没有指定任何方向性,因为我认为您确实想在这种情况下获得两个方向。 But you should also specify directionality in that clause, if appropriate. 但是,如果合适,您还应该在该子句中指定方向性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.