0
votes

I'm using the variable length relationship feature in a cypher query, and it seems to be mostly working. However I want to include the intermediate node(s) if any in the results and I can't figure out how to best achieve this.

A simplified example is a query like this

MATCH (a:MOL)-[:F2EDGE*1..2]-(b:MOL) RETURN a,b LIMIT 100

The a and b nodes are retrieved as expected and in a few cases they are connected where the path length is 1. But in most cases they are disconnected because the intermediate node (path length 2) is not included in the results. The 2 hop query would look like this:

MATCH (a:MOL)-[:F2EDGE]-(i:F2)-[:F2EDGE]-(b:MOL) RETURN a,i,b LIMIT 100

How can I achieve this?

1

1 Answers

1
votes

You have to define a path and return it like that :

MATCH p=(a:MOL)-[:F2EDGE*1..2]-(b:MOL) RETURN p LIMIT 100