Return count of relationships instead of all

I wonder if anyone can advise how to adjust the following query so that it returns one relationship with a count of the number of actual relationships rather than every relationship? I have some nodes with many relationships and it's killing the graph's performance.

MATCH (p:Provider{countorig: "XXXX"})-[r:supplied]-(i:Importer)
RETURN p,  i limit 100

Image of node with many relationships

Many thanks

1 answer

  • answered 2022-05-07 22:15 Kaan

    To return the relationship name along with a count, change your "return" statement, like this:

    MATCH (p:Provider{countorig: "XXXX"})-[r:supplied]-(i:Importer)
    RETURN type(r), count(r)
    

    Using type(r) will return the type of the relationship, which looks to be "supplied" in your example. And then count(r) is just using the built-in function to count the number of occurrences of that relationship in the query.

How many English words
do you know?
Test your English vocabulary size, and measure
how many words do you know
Online Test
Powered by Examplum