cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Retrieve edge at which path matching fails

Hello, I am wondering what the best way is to retrieve the first missing edge that causes a path match to fail.

For example, say I want to match instances of the path (C1:Compound)-[:Contained_in]-(:Experiment)-[:Originates_from]-(L1:Lab) starting from a specific (C1:Compound) node and ending at a specific (L1:Lab) node.

If no edges (C1:Compound)-[:Contained_in]-(:Experiment) exist, then the path matching fails at that first edge of the pattern, rather than at the second (which is (:Experiment)-[:Originates_from]-(L1:Lab) as above). This difference is important in my case and I need a way to retrieve the edge at which path matching fails.

I really appreciate any advice on this! Cheers, Terence

1 REPLY 1

You can try this:

optional match (C1:Compound)-[r1:Contained_in]-(e:Experiment)
optional match (e)-[r2:Originates_from]-(L1:Lab) 
return C1, r1, e, r2, L1

 Or, if you just need to know which ones exists, you can return just the id of each:

optional match (C1:Compound)-[r1:Contained_in]-(e:Experiment)
optional match (e)-[r2:Originates_from]-(L1:Lab) 
return id(C1), id(r1), id(e), id(r2), id(L1)

This should tell you if a link exists between C1 and an 'Experiment' node. If it does, it should also tell you if a link exists between the 'Experiment' node and the L1 node.