neo4j'在另外两个节点之间显示节点

时间:2016-04-28 08:11:06

标签: neo4j

我在两种类型的节点之间有以下关系(:Application,:City): InstalledIn UsedFrom

  

App InstalledIn City   App UsedFrom City

这意味着应用程序(软件)安装在NewYork并在伦敦使用。

Relationships

现在我想看看城市之间的关系(UsedFrom)。我想要一个没有应用程序的视图来自城市A的用户使用来自城市B的applcation。 在上面的示例中(City London - AccessesApplicationIn NewYork)

我怎么能意识到这一点?

1 个答案:

答案 0 :(得分:0)

1)添加数据:

MERGE (a1:App {name:'app1'})
MERGE (a2:App {name:'app2'})
MERGE (c1:City {name:'London'})
MERGE (c2:City {name:'New York'})
MERGE (a1)-[:INSTALLED_IN]->(c2)
MERGE (a2)-[:INSTALLED_IN]->(c2)
MERGE (a1)-[:USED_FROM]->(c1)
MERGE (a2)-[:USED_FROM]->(c2)

enter image description here

2)现在我们找到了城市之间的关系:

MATCH (c1:City)<-[:USED_FROM]-(a:App)-[:INSTALLED_IN]->(c2:City)
RETURN DISTINCT 'City ' + c1.name 
     + ' - [:AccessesApplicationIn] -> ' + 
       'City ' + c2.name 
AS AccessesApplicationIn

<强> AccessesApplicationIn

City New York - [:AccessesApplicationIn] -> City New York
City London - [:AccessesApplicationIn] -> City New York

<强> UPD

3)查询的另一个选项:

MATCH path=(:City)-[r:AccessesApplicationIn]-(:City) DELETE r 
RETURN PATH
UNION
MATCH (c1:City)<-[:USED_FROM]-(a:App)-[:INSTALLED_IN]->(c2:City)
MERGE path=(c1)-[:AccessesApplicationIn]->(c2)
RETURN DISTINCT path

enter image description here