Neo4j:有没有快速获取两个节点之间距离的方法?

ine*_*sha 2 neo4j

我在链中有节点,如下所示:

(a)<-[:rel]-(b)<-[:rel]-(c) ... (x)
Run Code Online (Sandbox Code Playgroud)
  • 每个节点都有一个唯一的索引。
  • 这条链上有几十万个节点。

(a)是否有一种快速方法来计算和之间的节点(或关系)数量(x)即使它们之间有数千个节点?到目前为止,p=(a)<-[:rel*]-(x)进展“缓慢”。

注意:我不需要知道之间的节点的任何信息,我只想找到距离。

JF *_*ier 5

使用最短路径方法:

MATCH (martin:Person { name:"Martin Sheen" }),(oliver:Person { name:"Oliver Stone" }), 
p = shortestPath((martin)-[*..15]-(oliver))
RETURN length(p)
Run Code Online (Sandbox Code Playgroud)

https://neo4j.com/docs/developer-manual/current/cypher/#query-shortest-path