繁体   English   中英

如何显示 neo4j 中的所有节点和两个节点之间的关系?

[英]How can i display the all nodes and relationships between two nodes in neo4j?

创建 Year 和 Month 节点并将它们连接到 Employee 节点。 这是 Cypher:

MERGE (y:Year {year:toInteger(line.YearofJoining)})
MERGE (m:Month {month:line.MonthNamofJoining)})
MERGE (y)-[:MONTH]->(m)

MERGE (a:Employee {empid:line.EmpID, firstname:line.FirstName, lastname:line.LastName, 
gender:line.Gender})
MERGE (m)-[:EMPLOYEE]->(a)

如何显示两个节点之间的节点和关系? 例如,如果我 select 有两个不同的员工 id,这里我想显示两个员工之间的关系是什么(将两个员工作为共同属性名、姓、月、年等)

提前致谢

使用此查询,您可以获得两个节点之间的所有关系

MATCH (n1)-[r]->(n2) 
RETURN {type: type(r), nodes: {n1: n1{.*}, n2: n2{.*}}}

OR

MATCH (n1)-[r]->(n2) 
RETURN {type: type(r), nodes: {n1: collect(distinct n1{.*}), n2: collect(distinct n2{.*})}}

通过公共属性获取员工:

MATCH (e:Employee)-[]-(m:Month) 
return {
  month: m.month, // You can replace it with any property you want to group for example "gender: e.gender"
  employees: collect(distinct e{.*})
} as byMonth

编辑

如何知道与给定 Employee id 相似的其他员工。 例如,我在一家公司工作(我的年龄、位置、加入年份作为数据),我想知道公司中具有相似关系的员工,例如相同年龄、加入年份、加入月份、位置等.w.r.t 给我

下面的查询应该工作

match (employee:Employee) where employee.empid= 1
optional match (employee)-[:EMPLOYEE]-(month:Month{month: 10})-[:EMPLOYEE]-(other:Employee) 
optional match (other) where other.monthOfJoining = employee.monthOfJoining or other.yearOfJoining = employee.yearOfJoining or other.age = employee.age
return employee, other

编辑 2

获取与两个或多个节点相关的所有公共节点的计数

MATCH (node1:Employee)-->(r)<--(node2:Employee)

with count(r) as maxCountRelation, node1{.*} as e1, node2{.*} as e2

return {commonRelation: maxCountRelation, employees: collect(distinct e1)+collect(distinct e2)} as result order by result.commonRelation desc limit 1

暂无
暂无

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

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