Reputation: 9
My start node is A . End node is E.
What can be the cyper query in neo4j such that I will get the result as
path one : A > b > c > d >e
path two : A > b > c > f > g > e
I have tried :
MATCH p = (n)-[*]->(m) where n.name='A' and m.name='E' return p
but I am getting complete node list not the seperated one.
Thanks in advance
Upvotes: 0
Views: 365
Reputation: 2666
Lets see the graph you have :
CREATE (a:Node {name: "A"})
CREATE (b:Node {name: "B"})
CREATE (c:Node {name: "C"})
CREATE (d:Node {name: "D"})
CREATE (e:Node {name: "E"})
CREATE (f:Node {name: "F"})
CREATE (g:Node {name: "G"})
MERGE (a)-[:HAS]->(b)-[:HAS]->(c)-[:HAS]->(d)-[:HAS]->(e)
MERGE (c)-[:HAS]->(f)-[:HAS]->(g)-[:HAS]->(e);
That is correct ?
Well then, the statement you wrote returns two paths ... sure, the visualization in the browser will show the full graph, but look at the other formats and you'll see you're getting two "rows" each containing a path.
You can see this by trying the following :
MATCH p=(n1:Node)-[*]-(n2:Node)
WHERE n1.name="A"
AND n2.name="E"
RETURN p LIMIT 1;
That will return only one path and the browser will show only one. It's just a matter of correctly interpreting/processing your results. This will show the second path only :
MATCH p=(n1:Node)-[*]-(n2:Node)
WHERE n1.name="A"
AND n2.name="E"
RETURN p SKIP 1 LIMIT 1;
Hope this helps, Tom
Upvotes: 1