neo4jcypher

How to count the numbers of node types in the Neo4j graph?


MATCH (p:Product), (s:Student), (b:Boy), (a:Attribute)
RETURN count(distinct(p)), count(distinct(s)), count(distinct(b)), count(distinct(a))

I want to know how many counts of each node types in the graph using this query. However, the Neo4j Browser gives a warning saying that this query produces a cartesian product. Is there a better way to write the query?


Solution

  • To get a variety of statistics for your DB, including a count of the number of nodes for every label, you can use the APOC function apoc.meta.stats.

    The following query gets just the label node counts, returning a map of label names to node counts:

    CALL apoc.meta.stats() YIELD labels
    RETURN labels;