Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
544 views
in Technique[技术] by (71.8m points)

neo4j - Cypher query gives unnecessary relationships

I am trying to display only one relevant relationship in the cypher query web browser but it displays all the relationships in between nodes. I am running following query:

MATCH (emp:Employee)-[e:EMPLOYED {dateendrole:"Current"}]->(c:Company {companyname:"xyza"})
MATCH (emp)-[ea:EDU_ASSOCIATED]->(ec:Company)
MATCH (another_emp:Employee)-[ea1:EDU_ASSOCIATED {overlapyearstart:ea.overlapyearstart, overlapyearend:ea.overlapyearend}]->(:Company {comp_id:ec.companyId})
RETURN emp, e, c, ea, ec, another_emp, ea1,  LIMIT 1;

My intention in the above query is to find associated employees into another company where an employee employed currently in one company and it was or has been employed to another company. For example, find associated employees in some company where an employee has worked before in that company and currently working in the xyza company.

Here, the employee and company is the nodes. It has associated relationship which contains their overlap years as properties of the relationship. e.g. (emp)-[:Associated{overlapyearstart:x, overlapyearend:y}]->(company)

If the employee has worked with another employee at some company then overlap years will be same.

The above query gives following output in the web interface of the neo4j. enter image description here

In the image, "Mr"(nodes dosen't display proper names) is the employee. "United States" is current of employer. "Unknown" is company he/she worked in the past and "Doctor" is the associated employee to "Mr" at the "Unknown" company.

I've two questions:

  1. From "Doctor" to "Unknown", why it displays all the relationships? How can I show only one relevant relationship? Currently it shows all "Doctor" to "Unknown" relationship.

  2. How can I do the same as above for "Mr" to "Unknown"?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I believe that these relationships are only present in the Graph Visualization Mode of Neo4j Browser. If you change your visualization mode to "Text", "Table" or "Code" these relationships will not be shown. That is: the Graph visualization mode is trying to "complete" the graph for you.

To achieve the desired result you should go to the section "Graph Visualization" of Neo4j Browser Settings and uncheck the option "Connect result nodes" as show in the image below:

Neo4j Browser Settings


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...