简体   繁体   English

Neo4j获得1度节点之间的边缘

[英]Neo4j get edges between 1st degree nodes

Assume i have graph relations defined as A->B, A->D, C->A, B->C, B->D. 假设我具有定义为A-> B,A-> D,C-> A,B-> C,B-> D的图形关系。 I need to get the following subgraph in Neo4j - 我需要在Neo4j中获得以下子图 -

  1. Get all 1st degree connections (indegree or outdegree) of a node ie For node A, it would be B, C, D 获取节点的所有1度连接(indegree或outdegree),即对于节点A,它将是B,C,D
  2. Get all the edges between these 1st degree nodes. 获得这些第一度节点之间的所有边缘。 Since B,C,D are 1st degree connections, edges would be B->C, B->D 由于B,C,D是1度连接,边缘将是B-> C,B-> D.

For the 1st part, I have the following query - 对于第1部分,我有以下查询 -

MATCH (s:Node)->(d:Node) 
WHERE s.name = 'A' OR d.name = 'A'

I'm not able to get the 2nd part of the data in the same query. 我无法在同一查询中获取数据的第二部分。 Do i need to iterate through all the nodes? 我需要遍历所有节点吗?

This is a simple pattern that says that you start the path from the node, then go to the node next to it, then one of which you can return to the starter node: 这是一个简单的模式,表示您从节点开始路径,然后转到它旁边的节点,然后其中一个可以返回到起始节点:

MATCH (A:Node {name:'A'}) WITH A
MATCH (A)--(FD1:Node)-[r]-(FD2:Node)--(A) 
  WHERE ID(FD1) > ID(FD2)
RETURN FD1, r, FD2

PS And remember that you can not specify the direction of the relationship. PS并记住你不能指定关系的方向。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM