简体   繁体   English

如何使用密码查询在neo4j中找到特定关系类型的连接最紧密的节点?

[英]How to find the most connected node of particular relationship type in neo4j using cypher query?

Can some one help me to find the most connected node of particular relationship type in neo4j using cypher query. 有人可以帮助我使用密码查询在neo4j中找到特定关系类型中连接最紧密的节点。

Suppose I have 假设我有

Node1 Node2 Relationship Node1 Node2关系
A B follows A B跟着
A C follows C跟随
B D follows B D跟着

A D follows D跟随

Here Node D is the most connected node.of particular relationship type "Follows" .so how to find this node using cypher query? 这里节点D是连接最紧密的节点。特定关系类型为“跟随”。那么如何使用密码查询找到该节点?

Thanks in Advance 提前致谢


(Edit): i found my answer tnx Martin Preusse (编辑):我找到了答案tnx Martin Preusse

  MATCH (n)<-[r:FOLLOWS]-() RETURN n, count(r) AS num ORDER BY num desc 

Try this if the direction of the relationship matters (will only return A and B ): 如果关系的方向很重要,请尝试以下操作(只会返回AB ):

MATCH (n)-[r:follows]->()
RETURN n, count(r) AS num
ORDER BY num

Or this if you don't need the direction (ie the node D will be returned as well): 如果不需要方向,也可以这样(即节点D也将被返回):

MATCH (n)-[r:follows]-()
RETURN n, count(DISTINCT r) AS num
ORDER BY num

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

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