在neo4j中获取与查询匹配的所有节点的所有连接节点

时间:2018-05-04 10:36:56

标签: neo4j cypher

我的neo4j db中有两种类型的节点

Skill and SkillCluster

技能节点作为一个或多个SkillCluster节点的有向边[BelongsTo关系]。我想找到属于特定技能群集的所有技能名称及其连接技能群名称。我写了一个查询来查找属于这样的技能群的所有技能 -

match(cluster:SkillCluster {Name: 'Engineering'})<-[:BelongsTo]-(skill:Skill) return skill.Name, cluster.Name;

此查询返回此输出

skill.Name                                      cluster.Name
"Dxdesigner"                                    "Engineering"
"Electromagnetic Interference (EMI) Engineer"   "Engineering"
"SEAM 3D"                                       "Engineering"
"Electromagnetic Interference (EMI) Mitigation" "Engineering"

技能Dxdesigner连接到2个技能群集节点,但我的查询没有返回它们。

1 个答案:

答案 0 :(得分:1)

尝试:

match(cluster:SkillCluster {Name: 'Engineering'})<-[:BelongsTo]-
                                       (skill:Skill)-
                                       [:BelongsTo]->(cluster2:SkillCluster) 
return skill.Name, cluster.Name, cluster2.Name;

此外,您不需要返回cluster.Name,因为您已将Name设置为“Engineering”。所以它总是会回归工程。

更新:根据InverseFalcon的评论:

match(cluster:SkillCluster {Name: 'Engineering'})<-[:BelongsTo]-
                                       (skill:Skill)-
                                       [:BelongsTo]->(cluster2:SkillCluster) 
return skill.Name, collect(cluster2.Name) + cluster.Name as clusters;