Search code examples
neo4jcypherpath-finding

Is it possible to match paths between two lists of nodes?


I try:

match (a1 {name: "a1"}) match (a2 {name: "a2" }) 
with [a1,a2] as A
match (b1 {name: "b1" }) match (b2 {name: "b2"}) 
with A,[b1,b2] as B
match p=A--B
return p

But it doesn't work.

How should I tell it to find any path between the two groups? Yes I can try individual pair of nodes, but the number of combinations I need to try is huge. The Neo4j Cypher Manual of Cypher path matching and Lists don't help me on this.


Solution

  • What about changing the last part of your query to

    match p=(A)—(n)
    Where n IN B
    return p