Return type matched from multiple relationships in Neo4j with Cypher

I know that you can match on multiple relationships in Neo4j, like this example in the docs:

MATCH (wallstreet {title: 'Wall Street'})<-[:ACTED_IN|:DIRECTED]-(person)

which returns nodes with an ACTED_IN or DIRECTED relationship to 'Wall Street'.

However, is there a way to get the type of the relationship in this query? That is, I would like to return not only the name, but also which relationship applies to him/her, in order to see if it was the ACTED_IN, or the DIRECTED relationship that caused the result to be output.

You can do the equivalent here:

MATCH (:Person {name: 'Oliver Stone'})-[r]->(movie)
RETURN type(r)

but that's just matching on any relationship. I would like to do this, but only with the two relationships specified in the clause.


1 answer

  • answered 2021-11-23 01:50 Cobra

    You no longer need additional colons in between valid edge types you are querying. otherwise you can use the variable just like you did in the unspecific edge case:

    MATCH (:Movie{title: 'The Matrix'})<-[r:ACTED_IN|DIRECTED]-(person)
    RETURN type(r),

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