cancel
Showing results for 
Search instead for 
Did you mean: 

Visualize direct and indirect relationships

Hi All,
I have a graph with the following relationships:
A -> B -> C & A-> C.
And I want to show All A->C instances including the implied ones (A->B->C).

For eg:
A(John) -> Works_At -> C(Apple)
A(Tony) -> has_ID ->B(123)
B(123) -> IsEmployedAt -> C(Facebook)

I want to visualize in one view:
John-> Apple
Tony->Facebook

Can someone please help me with this.
I have tried creating a virtual relationship A->B->C but it returns no results.

TIA.

1 ACCEPTED SOLUTION

Joel
Ninja
Ninja

A union may give you what you want, something like this (still slightly pseudo code, but more cypher like)

MATCH (A)-[:has_ID]->(B)-[:IsEmployedAt]->(C)
return A,C
UNION
MATCH (A)-[:Works_At]->(C)
return A,C

either directly as a list or as input to create the virtual relationships? Though, I suspect you might also want to do a distinct A,C after the UNION to avoid potential duplicates.

View solution in original post

2 REPLIES 2

Joel
Ninja
Ninja

A union may give you what you want, something like this (still slightly pseudo code, but more cypher like)

MATCH (A)-[:has_ID]->(B)-[:IsEmployedAt]->(C)
return A,C
UNION
MATCH (A)-[:Works_At]->(C)
return A,C

either directly as a list or as input to create the virtual relationships? Though, I suspect you might also want to do a distinct A,C after the UNION to avoid potential duplicates.

chandan202_aliv
Node Clone

Hi,

The following query might solve your problem:
Match (a:PERSON)-[:WORKS_AT|HAS_ID]->(b)
Optional Match (b)-[:IS_EMPLOYEED_AT]->(c)
Return a.name As PERSON NAME,
Case
When b.name is null
Then b.id
Else b.name
End As COMP/EMP-ID,
c.name As COMPANY NAME

In this query we can use the regular expression operator union over the edge labels to find both company and empid of the person if such relationships in the database exist.
Then the optional match is used to search if node b has an outgoing edge to the company node and the edge label is :IS_EMPLOYED_AT. The optional match returns null if no such edges and subsequent nodes exists.

In case you just wish to visualize the relationships found by the MATCH clause then in the return clause simply return a,b,c