cancel
Showing results for 
Search instead for 
Did you mean: 

Query ShortPath based on Attribute

Hi All,
Someone already tried to get one Path based on some attribute ? I'm trying this one:
MATCH (r1:EndNode { Name:'aaa'}),(r2:EndNode { Name:'bbb'})
MATCH p = allShortestPaths((r1)-[r*]-(r2)) WHERE r.Denied <> 'TESTONE' return p
Without WHERE cause works. but when I try to filter doesn't works.

3 REPLIES 3

koji
Ninja
Ninja

Hi @fabiooliveirasantos

Neo4j 4.2.1

This is the data.

CREATE (r1:EndNode {Name: 'aaa'})-[:REL {Denied: 'HOGEHOGE'}]->(r2:EndNode {Name: 'bbb'}),
       (r1)-[:REL {Denied: 'TESTONE'}]->(:EndNode {Name: 'ccc'})-[:REL {Denied: 'TESTONE'}]->(r2),
       (r1)-[:REL {Denied: 'TESTONE'}]->(:EndNode {Name: 'ddd'})-[:REL {Denied: 'TESTONE'}]->(r2);


This Cypher will work with the current version.

MATCH (r1:EndNode {Name: 'aaa'}), (r2:EndNode {Name: 'bbb'})
MATCH p = allShortestPaths((r1)-[r*]-(r2))
  WHERE ALL(r IN relationships(p) WHERE r.Denied = 'TESTONE')
RETURN p;

I think this one doesn't works on 3.4 version, b/c I saw all links (even with Denied set to HOGEHOGE) in result....Any other idea?

I think that the problem is related with Neo4j web browser interface and not server. I made the same query using python (py2neo) and saw the correct topology (avoiding HOGEHOGE edges).. So your query works perfectly. So many thanks Sr.

Nodes 2022
Nodes
NODES 2022, Neo4j Online Education Summit

On November 16 and 17 for 24 hours across all timezones, you’ll learn about best practices for beginners and experts alike.