我有以下图形模型来表示微服务架构
(:Team {space})-[:OPEX]->(:Service)-[:USES]-> [:Service]
我的自然语言查询:
我在用优雅的Cypher查询表达此查询时遇到问题。我提出了以下内容,但是必须有一种更轻松,更自然的表达方式。
MATCH (t1:Team {space:"shopping"})-[o1:OPEX]->(s1:Service),
(t2:Team {space:"shopping"})-[o2:OPEX]->(s2:Service),
(s3:Service)-[u:USES]->(s4:Service)
WHERE s3.name=s1.name AND s4.name=s2.name
RETURN t1, o1, s1, u, s2, o2, t2
有人可以指出我的方向吗?
答案 0 :(得分:1)
您应该重用引用同一实例的变量,并且可以使用IN和COLLECT在一组节点中查找模式。
类似这样的东西
MATCH (:Team {space:"shopping"})-[:OPEX]->(s:Service)
WITH COLLECT(s) as services
MATCH (t:Team {space:"shopping"})-[o:OPEX]->(s1:Service)
OPTIONAL MATCH (s1:Service)-[u:USES]->(s2:Service)
WHERE s1 in services AND s2 in services
RETURN t, o, s1, u, s2