Reputation: 374
I'm trying to create a cypher query that returns me the nodes connected by a given range of hops (i.e. 1..5), where all the relationships between these hops share a same attribute value, without specifying this attribute.
So I would like to do something like
MATCH (a {type: 'cin1'})-[rels:Next*1.. {value: 1}]->(b {type: 'cancer'})
RETURN (a), (b)
But without specifying that the value on the edges should be one, they just need to be equal among all the edges in the hopping process.
Upvotes: 1
Views: 263
Reputation: 41706
I would add an upper bound to your path. Or use (all)shortestPath(s)
Also make sure to look up a
and b
by indexed label + property combination.
And then you can use a predicate on the relationships-collection that forms your path.
MATCH (a:Label {type: 'cin1'})
MATCH (b:Label {type: 'cancer'})
MATCH shortestPath((a)-[rels:Next*1..20]->(b))
WHERE ALL(r in tail(rels) WHERE (head(rels)).value = r.value)
RETURN (a), (b)
Upvotes: 1