1
votes

Im trying to find all paths between two nodes in neo4j db

the query i used to get all paths returns error, while it works when I change allSimplePaths to shortestPath to get the shortest path:

MATCH (from), (to) , 
paths = allSimplePaths((from)-[*]->(to)) 
WHERE from.ID ='3007' AND to.ID in ['5575','8150', '3674']
Return paths

returns error message:

Invalid input '(': expected an identifier character, node labels, a property 
map, a relationship pattern, ',', USING, WHERE, LOAD CSV, START, MATCH, UNWIND, 
MERGE, CREATE, SET, DELETE, REMOVE, FOREACH, WITH, CALL, RETURN, UNION, ';' or 
end of input (line 2, column 23 (offset: 82))
"paths = allSimplePaths((from)-[*]->(to)) "
1
Are you sure you want "all paths"? That's potentially a lot of data and has serious performance implications.Tim Kuehn
Im still experimenting with my data to find an optimal query.Zingo

1 Answers

1
votes

allSimplePaths and allPaths are graph algorithms supported by the neo4j REST API, but not Cypher.

To get the equivalent of allPaths, you could just do this:

MATCH (from), (to), paths = (from)-[*]->(to)
WHERE from.ID ='3007' AND to.ID in ['5575','8150', '3674']
Return paths

You will need to use the REST API to use allSimplePaths.