[英]Neo4j: How to get additional nodes from nodes in a path?
I have nodes in a chain, like this: 我有一个链中的节点,像这样:
(n {height:100})
|
(n)
|
(n)
|
(n)
|
(n)
I can get these nodes with this cypher query: 我可以通过以下密码查询获得这些节点:
MATCH chain=(start :n {height:100})-[:chain*4]->(end :n)
RETURN chain
However, each node in this chain also has a single node coming off it with a specific relationship, like this: 但是,此链中的每个节点也都有一个具有特定关系的单个节点,如下所示:
(n)-[:single]->(o)
|
(n)-[:single]->(o)
|
(n)-[:single]->(o)
|
(n)-[:single]->(o)
|
(n)-[:single]->(o)
I would like to return each (n)
, as well as the (o)
coming off it. 我想返回每个
(n)
,以及返回的(o)
。
Is it possible to do this in one cypher query? 是否可以在一个密码查询中执行此操作?
Shouldn't be a problem, though this is easier if we don't match on the path, but get all nodes in the chain (and the single node off of each) instead. 应该不会有什么问题,但是如果我们在路径上不匹配,这会更容易,但是可以让链中的所有节点(以及每个节点中的单个节点)代替。
MATCH (start :n {height:100})-[rels:chain*0..4]->(chainlink :n)-[:single]->(o)
RETURN chainlink, o
ORDER BY SIZE(rels)
Okay, it seems the use of WITH(chain)
and UNWIND
does the trick: 好的,似乎使用
WITH(chain)
和UNWIND
可以解决问题:
MATCH chain=(start :n {height:100})-[:chain*4]->(end :n)
WITH NODES(chain) AS nodes
UNWIND nodes as node
OPTIONAL MATCH (node)-[:single]->(o :o)
RETURN nodes, COLLECT(o) as os
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.