Neo4j - Cypher query for finding neighbourhood graph

…衆ロ難τιáo~ 提交于 2019-12-11 13:38:39

问题


For the below graph...

I am struggling to compose a Cypher query that will return me the neighbourhood graph (relationships) of node 1. The neighbourhood graph of 1 includes the nodes connected by the relations I have marked with dotted lines. These are the nodes pointing to 1, pointed at by 1 and all other inter-connections between these nodes.

This below query

START a=node(15151) MATCH (a)-[r]-(b) RETURN r

gives me back the relations between 1 and 2,3,4,5 but I also need the relations between 2-4 and 3-5 to be returned in the same query.


回答1:


Try this

  START a= node(15151) MATCH (a)-[r1]-(b) WITH a,b,collect(b) as bAll,r1 
   MATCH (b)-[r2]->(c) WHERE (c IN bAll) and a <> c return r1,r2


来源:https://stackoverflow.com/questions/21471368/neo4j-cypher-query-for-finding-neighbourhood-graph

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!