Search code examples
neo4jcypherneo4j-apoc

How do I return the count of each relationship type from apoc.path.subgraphall in neo4j?


I'm working with the basic data set that neo4j provides from the :play movies command.

I am attempting to first find the subgraph that a specific nodes is connected to, which I do with this call:

MATCH (movie:Movie) WHERE movie.title = "Cloud Atlas" CALL apoc.path.subgraphAll(movie, {}) YIELD nodes, relationships RETURN nodes, relationships;

This returns all of the nodes and the relationships in this particular graph, which is fine. But I am looking for a way to get the count of each specific relationship type in the graph that is returned.

In the top bar, these numbers are already displayed. ie: REVIEWED(9), PRODUCED(15), WROTE(10), etc.

How would I get these values?


Solution

  • This query will return each relationship type and a count for that type:

    MATCH (movie:Movie) WHERE movie.title = "Cloud Atlas"
    CALL apoc.path.subgraphAll(movie, {}) YIELD relationships 
    UNWIND relationships AS r
    RETURN TYPE(r) AS type_r, COUNT(*) AS num