给出如下数据库:
A F
/ \ \
B C G
/
D
我想要一组A所涉及的所有关系。这个查询是我能做的最好的,但返回A图中的所有节点对,重复共享关系:
START start = node(A)
MATCH (start)-[rel*]->(child)
RETURN rel, child;
如何做到最好?
答案 0 :(得分:3)
我需要这样的东西(由Peter Neubauer建议):
START s = node:node_auto_index(name="A")
MATCH (s)-[:CHILD*0..]->(parent),
path=(parent)-[:CHILD]->(child),
(child)-[:CHILD*0..]->(leaf)
WHERE NOT leaf-[:CHILD]->()
WITH DISTINCT path AS path
RETURN EXTRACT(n IN NODES(path): n.name)
更简洁的版本:
START s = node:node_auto_index(name="A")
MATCH (s)-[:CHILD*0..]-( ss ),
path = ( ss )-[:CHILD]->(child)
WITH DISTINCT path AS path
RETURN EXTRACT(n IN NODES(path): n.name)