Filter nodes by its degree

18 views
Skip to first unread message

Zhixuan Wang

unread,
Apr 3, 2017, 9:41:12 PM4/3/17
to Neo4j
I found my query always got stuck at expanding some messy nodes with hundreds of indegrees. I am wondering if on each node we have some hidden property that tells the number of degrees of that node?

I believe with the concept of "index free adjacency" there should be a way of knowing the node degrees without actually going out to read every node it is connected to.

Any comments/suggestions would be greatly appreciated.

Thanks,

Max De Marzi Jr.

unread,
Apr 5, 2017, 1:03:25 AM4/5/17
to Neo4j
Oh yeah. We keep track of them.  
You can use SIZE((node)-[:reltype]->()) in Cypher. 

MATCH (n:User {id:'max'})
RETURN SIZE((n)--()) AS all, SIZE((n)-->()) AS out, SIZE((n)<--()) AS in, SIZE((n)-[:FRIENDS]-()) AS allType, SIZE((n)-[:FRIENDS]->()) AS outType, SIZE((n)<-[:FRIENDS]-()) AS inType

In Java you have node::getDegree(). See https://maxdemarzi.com/2017/04/04/building-a-twitter-clone-with-neo4j-part-three/ for example of using it.

Zhixuan Wang

unread,
Apr 5, 2017, 3:37:13 PM4/5/17
to Neo4j
thanks Max, that is exactly what I want
Reply all
Reply to author
Forward
0 new messages