I am building a social network like graph where we periodically would like to find all the nodes with an incoming count of greater than 2. E.g.
A->B
C->B
C->A
D->A
E->A
Should return node A.
I am new to neo4j and am still a bit confused about whether they will search through all the available rows. Is there an index I can use to optimize these queries? My search query is like this
EXPLAIN MATCH ()-[r:F]->(b:Person)
WITH b, count(r) AS count
WHERE count > 1
RETURN collect(b.username)
Thank you
CodePudding user response:
Neo4j has a special relationship count store that holds the number of relationships a node has. It allows to get the count of relationships without having to expand them.
You can access relationship count store values using the size()
function.
MATCH (b:Person)
WITH b, size((b)<--()) as size
WHERE size > 2
RETURN collect(b.username)