6.8. Multirelational (social) graphs

Figure 6.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"

"Maria"

"LOVES"

"Sara"

"FOLLOWS"

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