cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Count all relationships by a property

MATCH (:A)-[r]->(:A)
RETURN r.myProp as prop, count(r) as count

I'm wondering if there is a way to speed up this query. Currently with ~50 million relationships, it takes a long time.

1 REPLY 1

Reiner
Graph Buddy

Hi @mr.sheehan,
welcome to the community!

Depends on the structure of your graph. My first hint would be to add a type to the relationship, cause I assume myProp doesn't appear on all types of relationships but on one or only a few.

MATCH (:A)-[r:REL_TYPE]->(:A) ...

or, if more than one type is needed:

MATCH (:A)-[r:REL_TYPE1|RELTYPE2]->(:A) ...

Best,
Reiner