简体   繁体   English

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

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

Created Year and Month nodes and connected them to Employee node.创建 Year 和 Month 节点并将它们连接到 Employee 节点。 Here is the Cypher:这是 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)

How can I show the nodes and relationship between two nodes?如何显示两个节点之间的节点和关系? for example, if I select two different employee id, here I want to display what are the relationship between two employees (will two employees as common properties first name, Lastname, month, year etc..)例如,如果我 select 有两个不同的员工 id,这里我想显示两个员工之间的关系是什么(将两个员工作为共同属性名、姓、月、年等)

Thanks in advance提前致谢

With this query you can get all the relationship between two nodes使用此查询,您可以获得两个节点之间的所有关系

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{.*})}}

Get employees by common properties:通过公共属性获取员工:

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

EDIT编辑

How to know other employees similar to the given Employee id.如何知道与给定 Employee id 相似的其他员工。 for example, I was working for a company (my age, location, year of joining as data) and I want to know the employees in the company who has similar relationships like same age, year of joining, the month of joining, location etc. w.r.t to me例如,我在一家公司工作(我的年龄、位置、加入年份作为数据),我想知道公司中具有相似关系的员工,例如相同年龄、加入年份、加入月份、位置等.w.r.t 给我

Below query should work下面的查询应该工作

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

EDIT 2编辑 2

Get count of all common nodes related to two or more nodes获取与两个或多个节点相关的所有公共节点的计数

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