MDub
MDub

Reputation: 21

Neo4j nodes: showing a-c relations

I've the following relations: a-b-c:

MATCH (a)-[:relation_x]->(b)-[:relation_y]->(c)
RETURN a,c

Now a and c are not connected. Is there a way to show this relation, without showing b?

Same result with:

MATCH (a)-[*2]->(c)
RETURN a, c

Upvotes: 1

Views: 73

Answers (1)

Bruno Peres
Bruno Peres

Reputation: 16355

You can install APOC Procedures and do it using apoc.create.vRelationship. With tris procedure you can create a virtual relation between two nodes at query time. Try it:

MATCH (a)-[:relation_x]->()-[:relation_y]->(c)
CALL apoc.create.vRelationship(a,'relation_type',{},c) yield rel
RETURN *

The output will be:

Output

Note: Remember to install APOC procedures according the version of Neo4j you are using. Take a look in the Version Compatibility Matrix.

Upvotes: 1

Related Questions