简体   繁体   English

获取所有路径neo4J Cypher

[英]Get all paths neo4J Cypher

I'm using neo4j to develop a proof of concept and I want to get all Nodes ID for all paths from my root node to leafs, example with ids : 我正在使用neo4j开发概念证明,我想获取从我的根节点到叶子的所有路径的所有Nodes ID,例如ids:

ROOT1-->N1--->SN2--->L1
ROOT1-->N2--->SN3--->L3

What I want to get in my result query is : ROO1,N1,SN2 and ROOT1,N2,SN3 我想在结果查询中得到的是: ROO1,N1,SN2 and ROOT1,N2,SN3

Im new to cypher and I struggle to get this result, any help would be usefull . 我不是cypher的新手,因此我很难获得这个结果,任何帮助都是有用的。

I assume that the ID that you mention is an id property. 我假设您提到的IDid属性。

To get a collection of the node ids in each full path (except for the leaf node): 要获取每个完整路径中的节点ID的集合(叶节点除外):

MATCH p=(root {id: 'ROOT1'})-[*]->(leaf)
WHERE NOT (leaf)-->()
RETURN EXTRACT(x IN NODES(p)[..-1] | x.id) AS result;

Here is a sample result: 这是一个示例结果:

+----------------------+
| result               |
+----------------------+
| ["ROOT1","N1","SN2"] |
| ["ROOT1","N2","SN3"] |
+----------------------+

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

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