Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Neo4j - Match by multiple relationship types

Tags:

neo4j

cypher

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.

like image 265
Stav Alfi Avatar asked Sep 09 '17 15:09

Stav Alfi


People also ask

How many relationships can Neo4j handle?

The standard store format of neo4j allows for 65k different relationship types.

Does Neo4j support bidirectional relationships?

Neo4j cannot store bidirectional relationships. No way around this, you can however treat relationships as bidirectional when querying your graph.

What does match do in Neo4j?

The MATCH clause allows you to specify the patterns Neo4j will search for in the database. This is the primary way of getting data into the current set of bindings. It is worth reading up more on the specification of the patterns themselves in Patterns.

How many directions can a relationship have in Neo4j?

Relationships describes a connection between a source node and a target node. Relationships always has a direction (one direction).


1 Answers

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
like image 185
Bruno Peres Avatar answered Oct 07 '22 23:10

Bruno Peres