Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

neo4j

cypher

Can some one help me to find the most connected node of particular relationship type in neo4j using cypher query.

Suppose I have

Node1      Node2     Relationship
A             B             follows
A             C             follows
B             D             follows

A             D             follows

Here Node D is the most connected node.of particular relationship type "Follows" .so how to find this node using cypher query?

Thanks in Advance


(Edit): i found my answer tnx Martin Preusse

    MATCH (n)<-[r:FOLLOWS]-()
    RETURN n, count(r) AS num
    ORDER BY num desc
like image 840
Milad ranjbar Avatar asked Jul 22 '16 10:07

Milad ranjbar


People also ask

How many nodes can a single relationship connect in Neo4j?

In other words, you want a relationship that connects more than two nodes. Mathematics allows this, with the concept of a hyperedge. This is impossible in Neo4j.

How do you show all nodes and relationships in Neo4j?

When you want to return all nodes, relationships and paths found in a query, you can use the * symbol. This returns the two nodes, the relationship and the path used in the query.

How many nodes a single relationship can connect?

Relationships. Relationships organize the nodes by connecting them. A relationship connects two nodes — a start node and an end node. Just like nodes, relationships can have properties.


1 Answers

Try this if the direction of the relationship matters (will only return A and B):

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

Or this if you don't need the direction (i.e. the node D will be returned as well):

MATCH (n)-[r:follows]-()
RETURN n, count(DISTINCT r) AS num
ORDER BY num
like image 173
Martin Preusse Avatar answered Oct 22 '22 11:10

Martin Preusse