How to write a MATCH statement for bidirectional relationship patterns?

63 Views Asked by At

As shown in the figure, there are two nodes with bidirectional relationships in the pattern that needs to be matched.

graph model

MATCH 
(a)-[e1:trans]->(b)-[e2:trans]->(c),
(a)-[e1:trans]->(b)<-[e3:trans]->(c)
return a,b,c,e1,e2,e3

The statement is not valid and will result in a "duplicate identifier e1" error.

Can you sugguest how to write this MATACH statement for this pattern? Thanks!

1

There are 1 best solutions below

0
Kelvin Lawrence On BEST ANSWER

I'm not sure about the Nebula Graph implementation, but with Cypher/openCypher in general, you cannot use the same relationship variable (e1 in this case) twice in a pattern. However, given you already have found b previously, your query can be simplified to

MATCH (a)-[e1:trans]->(b)-[e2:trans]->(c),
      (b)<-[e3:trans]-(c)
RETURN a,b,c,e1,e2,e3