[英]Neo4j return nodes connected by relationships of a given label and property
I am trying to find the nodes connected that are connected by the relationships having a given label and a given attribute. 我试图找到通过具有给定标签和给定属性的关系连接的节点。
For example I want to find all nodes connected by a relationship Edge
having as myID
123
例如,我要查找通过关系
Edge
连接为myID
123
所有节点。
I started from this query that returns the data on the relationships. 我从此查询开始,该查询返回有关关系的数据。
MATCH ()-[r:Edge{myID: "123"}]->()RETURN r;
Counting these relationships with 计算这些关系
MATCH ()-[r:Edge{myID: "123"}]->()RETURN count(r)
I get 45. 我得到45。
I then created the following: 然后,我创建了以下内容:
MATCH (a)-[r:Edge{myID: "123"}]->(b)RETURN a,b,r LIMIT 25
However this is not working: it seems to return much more nodes than expected: first of all LIMIT
is not limiting and hence the subgraph becomes very big and difficult to analyze but it seems that it is returning even nodes-relationship with a myID
property different than 123
, for sure more than 45. 但是,这不起作用:它似乎返回的节点比预期的要多得多:首先,
LIMIT
不是限制性的,因此子图变得非常大且难以分析,但似乎它甚至返回了具有myID
属性不同的节点关系。大于123
,肯定大于45。
How can I do that? 我怎样才能做到这一点?
EDIT 编辑
Take as example the following graph: 以下图为例:
//create 2 nodes
CREATE (: myNode{NID : 1});
CREATE (: myNode{NID : 1});
//create 2 relationships:
MATCH (n1:myNode{NID:1})
MATCH (n2:myNode{NID:1})
MErGE(n1)-[r:Edge{myID:2}]->(n2);
MATCH (n1:myNode{NID:1})
MATCH (n2:myNode{NID:2})
MErGE(n1)-[r:Edge{myID:2}]->(n2);
The problem can be seen trying the following queries that will return both the edges: 可以尝试以下将返回两条边的查询来查看问题:
MATCH p=(a)-[r:Edge{myID : 1}]->(b) return p limit 1;
MATCH (a)-[r:Edge{myID : 1}]->(b) return a,r,b limit 1;
If you are using the neo4j browser to enter queries and visualize the results, you should be aware of the browser's "Connect result nodes" option. 如果使用neo4j浏览器输入查询并可视化结果,则应注意浏览器的“连接结果节点”选项。 When that option is enabled, the browser automatically queries for (and displays) the relationships between the nodes returned by a Cypher query.
启用该选项后,浏览器会自动查询(并显示)Cypher查询返回的节点之间的关系。 (And note that a returned relationship references 2 nodes.)
(请注意,返回的关系引用了两个节点。)
You can enable/disable the "Connect result nodes" option by clicking the gear icon on the left side of the browser window, scrolling to the bottom of the Browser Settings panel, and checkmarking/uncheckmarking the "Connect result nodes" box. 通过单击浏览器窗口左侧的齿轮图标,滚动到“浏览器设置”面板的底部,并选中/取消选中“连接结果节点”框,可以启用/禁用“连接结果节点”选项。
Neo4J Browser by default tries to expand the nodes that are displayed in the view when nodes are returned. 默认情况下,Neo4J Browser尝试扩展返回节点时在视图中显示的节点。
Can you please try 你能试一下吗
MATCH p=(a)-[r:Edge{myID: "123"}]->(b) return p limit 25.
Neo4J Browser should not try to expand the nodes now. Neo4J Browser不应立即尝试扩展节点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.