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.

Why doesn't this relationship negate correctly?

lingvisa
Graph Fellow
MATCH (m ) -[r]- (n {nid:'123'}),
p = shortestPath((m)-[*..10]-(n))
WHERE NOT((m)-[:similar]-(n))
RETURN p limit 5

I want to find the shortest path between m and n, but they should not be linked by the relationship 'similar'. The query above will return 0 path, but if I remove the WHERE clause, it return all paths.

5 REPLIES 5

Do you get results if you use two separate matches, and keep the WHERE NOT clause associated with the first MATCH?

MATCH (m ) -[r]- (n {nid:'123'})
WHERE NOT((m)-[:similar]-(n))
MATCH p = shortestPath((m)-[*..10]-(n))
RETURN p limit 5

Still not, again only if I remove the WHERE clause.

Hi @lingvisa

What's the logic you are trying to implement?

Reading your query, m-r-n is already the shortest Path.

Am I missing something?

Bennu

I want to find shortest paths between two nodes, but exclude paths of a specific relationship 'similar'.

Hi!

So you wanna exclude :Similar from your paths?

Why isn't m queried with an specific property condition as well?

Bennu