1
votes

I'm wondering, within Cypher if there is a way to get a count of all nodes downstream of some node x.

For my particular use-case I have a number of graphs, which are separate entities, but stored in the same instance. I would like to find out, for each graph, what the node and relationship count is.

I already have this for relationships start r=rel() return count()

and this for nodes start n=node() return count()

for everything in the database.

Many thanks,

Eamonn

2

2 Answers

2
votes

If you have some "reference" or root node per subgraph you can use path expressions to find all nodes:

start root=node:roots(id="xx")
match root-[*..5]->end
return count(distinct end)

It makes sense to limit the depth of your search.

1
votes

you must index all your properties in your nodes/rels. then, you must start at these indexes to get the count, and if necessarily, sum them together for each graph. let's assume we got 2 graphs, book-author type and car-color type. then to get the overal sum of nodes for each graph in cypher:

start g1=node:node_auto_index('bookName:*'), g11=node:node_auto_index('authorName:*'),
      g2=node:node_auto_index('carName:*'), g22=node:node_auto_index('carColor:*')
return count(g1)+count(g11) as graph1, count(g2)+count(g22) as graph2

similary for all relationships. i don't know about any cypher solution which could simply group by an undefined property - that could solve the problem easily.