Neo4j - Match by multiple relationship types

Stav Alfi picture Stav Alfi · Sep 9, 2017 · Viewed 11.9k times · Source

I want to match between entities by multiple relationship types.

Is it possible to say the following query:

match (Yoav:Person{name:"Yoav"})-[:liked & watched & ... ]->(movie:Movie) return movie

I need "and" between all the relation types; Yova liked and watched and .. a movie.

Answer

Bruno Peres picture Bruno Peres · Sep 9, 2017

Yes, you can do something like:

match (gal:Person{name:"Yoav"})-[:liked|:watched|:other]->(movie:Movie) 
return movie

Take a look in the docs: Match on multiple relationship types

EDIT:

From the comments:

I need "and" between the relation types.. you gave me an "or"

In this case, you can do:

match (Yoav:Person{name:"Yoav"})-[:liked]->(movie:Movie),
(Yoav)-[:watched]->(movie),
(Yoav)-[:other]->(movie)
return movie