Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get degree of a node while filtering using MATCH in neo4j

Tags:

neo4j

cypher

I have a graph with 4 levels. While filtering using MATCH, how can i get the "degree" of a node? I am always getting a "degree" of 1.

Here is my query:

MATCH (k)-[r*]->(n:ABC)
WITH k,r,n,count(k) as degree
WHERE k.Value='30 ' AND degree > 1
RETURN n,r,k,degree;
like image 259
Don Mathew Avatar asked Dec 19 '22 23:12

Don Mathew


1 Answers

You are getting count of 1 because you aggregated over all 3, start-node, end-node, and all relationships in the path.

This is the most efficient way.

MATCH (k)
WITH k, size((k)-[:TYPE]->()) as degree
WHERE k.Value='30 ' AND degree > 1
MATCH (k)-[r:TYPE]->(n:ABC)
RETURN n,r,k,degree;
like image 143
Michael Hunger Avatar answered Jan 17 '23 16:01

Michael Hunger