HenrikRüping
HenrikRüping

Reputation: 119

Get all relationship types of a node efficiently

I have a node with a lot of neighbors (~1M). I would like to get a list of all relationship types of all the relations at this node (should be around 6 different types). Currently I am using

match (n:Label {indexedProperty:"value"}) match (n)-[r]-() return distinct type(r)

but this takes quite long (around 18 secs).

Is there a way to do this more efficiently in cypher ?

Upvotes: 1

Views: 150

Answers (1)

InverseFalcon
InverseFalcon

Reputation: 30397

APOC procedures can help here, try using apoc.node.relationship.types():

match (n:Label {indexedProperty:"value"})
return apoc.node.relationship.types() as types

That will get you a list of distinct types on the node.

Upvotes: 2

Related Questions