1

I am trying to figure out insights where (node1)-[:related_to]->(node2)-[:belongs_to]->(node3). I want to display like (node1)-[:belongs_to]->(node3) based on above relationship. Three relationship was created.

MATCH (n2:node2),(n3:node3)
WHERE n2.Name = n3.Name
CREATE (n3) <- [:BELONGS_TO]- (n2)

MATCH (n1:node2),(n2:node2)
CREATE (n1) <- [:related_to]- (n2)

MATCH (n1:node2),(n2:node2)
CREATE (n2) <- [:related_to]- (n1)

I have tried this query but it's giving me via relationship.

MATCH (n1:node1)-[r1:related_to]-(n2:node2)-[r2:BELONGS_TO]-(n3:node3) 
RETURN n1,n2,n3

I am new in this field and trying to bring few insights. Your valuable feedback will be appreciated.

Zara
  • 146
  • 1
  • 13

1 Answers1

0

if you have (n)-->(m)-->(p), the relationship (n)-->(p) doesn't exist in the database.

So to do what you want, you will need APOC. There are some procedures/functions to create virtual graph.

MATCH (n1:node1)-[r1:related_to]-(n2:node2)-[r2:BELONGS_TO]-(n3:node3) 
WITH n1, n3
CALL apoc.create.vRelationship(n1,'belongs_to',{​}, n3) YIELD rel
RETURN n1,n3, rel

Example : https://neo4j.com/docs/labs/apoc/current/virtual/

logisima
  • 7,340
  • 1
  • 18
  • 31