简体   繁体   English

与neo4j Cypher分开获取所有路径

[英]Get all path separately from neo4j Cypher

My graph 我的图

My start node is A . 我的起始节点是A。 End node is E. 结束节点为E。

What can be the cyper query in neo4j such that I will get the result as 可以是neo4j中的cyper查询,这样我将得到如下结果

path one : A > b > c > d >e 路径一:A> b> c> d> e
path two : A > b > c > f > g > e 路径二:A> b> c> f> g> e

I have tried : 我努力了 :
MATCH p = (n)-[*]->(m) where n.name='A' and m.name='E' return p 匹配p =(n)-[*]->(m),其中n.name ='A'和m.name ='E'返回p
but I am getting complete node list not the seperated one. 但是我得到的是完整的节点列表,而不是单独的节点列表。

Thanks in advance 提前致谢

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 希望这会有所帮助,汤姆

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM