5.10. Multirelational (social) graphs

Figure 5.8. Graph

This example shows a multi-relational network between persons and things they like. A multi-relational graph is a graph with more than one kind of relationship between nodes.

Query 

MATCH (me { name: 'Joe' })-[r1:FOLLOWS|:LOVES]->(other)-[r2]->(me)
WHERE type(r1)=type(r2)
RETURN other.name, type(r1)

The query returns people that FOLLOWS or LOVES Joe back.

Result

other.nametype(r1)
3 rows

"Maria"

"FOLLOWS"

"Sara"

"FOLLOWS"

"Maria"

"LOVES"

Try this query live create (_0 {`name`:"cats"}) create (_1 {`name`:"nature"}) create (_2 {`name`:"Ben"}) create (_3 {`name`:"Sara"}) create (_4 {`name`:"bikes"}) create (_5 {`name`:"Maria"}) create (_6 {`name`:"cars"}) create (_7 {`name`:"Joe"}) create _3-[:`FOLLOWS`]->_2 create _3-[:`FOLLOWS`]->_7 create _3-[:`LIKES`]->_0 create _3-[:`LIKES`]->_6 create _3-[:`LIKES`]->_4 create _5-[:`FOLLOWS`]->_7 create _5-[:`LOVES`]->_7 create _5-[:`LIKES`]->_6 create _7-[:`FOLLOWS`]->_5 create _7-[:`FOLLOWS`]->_3 create _7-[:`LOVES`]->_5 create _7-[:`LIKES`]->_1 create _7-[:`LIKES`]->_4 MATCH (me {name: 'Joe'})-[r1:FOLLOWS|:LOVES]->(other)-[r2]->(me) WHERE type(r1)=type(r2) RETURN other.name, type(r1)