简体   繁体   English

Neo4j返回节点通过给定标签和属性的关系连接

[英]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.

相关问题 从 Neo4j 图中获取给定跃点的节点和关系 - Get nodes and relationships at a given hop from a Neo4j graph Neo4j:如何查找所有节点:连接到具有特定属性的0个节点或具有属性集的所有节点 - Neo4j: How to find all nodes that: connected to either 0 nodes with specific property, or all nodes with property set Neo4j Cypher Query:查找连接到一个节点且具有 3 个以上其他关系的所有节点 - Neo4j Cypher Query: Finding all nodes, that are connected to a node, that has more than 3 other relationships 标签名称以对neo4j中的节点进行分组 - label names to group nodes in neo4j Neo4j:以特定的关系顺序查询两个节点之间的路径,并且仅知道最后一个节点的标签 - Neo4j: Query for a path between two nodes in a specific order of relationships and knowing only label of the last node 使用neo4j找到与给定节点有关系的节点集的有效方法 - Efficient way to find node set having relationships to given nodes using neo4j Neo4j 用属性分组节点 - Neo4j group nodes with property Neo4j:如何为具有多个关系的每对节点返回单个路径 - Neo4j: How to return a single path for each pair of nodes that have multiple relationships Neo4j中的关系与关系 - Relationships with relationships in Neo4j 在 Neo4j Cypher 中创建同类节点的关系 - Creating relationships of nodes of the same kind in Neo4j Cypher
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM