0

I am using the following neo4j cypher query on my graph:

MATCH (start:N1{id:'xyz'})
CALL apoc.path.expandConfig(start, {sequence:'N1, a>, N2, b>, N3, c>, 
N4', maxLevel:3}) YIELD path
RETURN path
ORDER BY length(path) DESC

Now I want to keep N3 as optional. Like if the link N2-b->N3 is unavailable, it should then check for N2-b->N4 and so on. I know I can do two separate queries and check. But is there a way to keep N3 optional in this query itself?

Thanks in advance!

1 Answers1

1

No, this currently isn't possible. If there was a different node to use instead this would work, as you could accept a different label in place of the node (or any node label if you didn't care), but there isn't a way to use the sequences here where the number of nodes/rels in the defined sequence isn't constant.

InverseFalcon
  • 29,576
  • 4
  • 38
  • 51
  • hm, would something like `CALL apoc.path.expandConfig(start, {sequence:'N1, a>, N2, b>|c>, N3|N4, c>|d>, N4|N5', maxLevel:3}) YIELD path` work? – Yashvardhan Nanavati Aug 07 '18 at 17:45
  • where if there are different labels and nodes at each level, we can optionally take the other instead of the first if the first one is non-existent? @InverseFalcon – Yashvardhan Nanavati Aug 07 '18 at 17:50
  • 1
    That could work, but keep in mind it wouldn't be one full path or the other (b>, N3, c>, N4 vs c>, N4, d> N5), so you could have (b>, N4, c>, N4) and other such possible combinations – InverseFalcon Aug 07 '18 at 22:03