简体   繁体   English

Neo4j cypher查询以获取与特定其他节点无关的所有节点

[英]Neo4j cypher query to get all nodes without a relationship to specific other node

I use Neo4j 2.3.1 and looking I am looking for a cypher query which gives me all nodes in the database which are not connected to the specific other node. 我使用Neo4j 2.3.1,我正在寻找一个密码查询,它给了我数据库中没有连接到特定其他节点的所有节点。 My Tree looks like this: 我的树看起来像这样:

在此输入图像描述

I know the red one and want to have a query which gives me the green ones. 我知道红色的那个,想要一个给我绿色的查询。 All of them do have the same relationship. 他们都有相同的关系。

EDIT: My question is misleading worded, so: What I want (as shown in the image) all nodes which are "above" a specific node and also their childs. 编辑:我的问题是误导措辞,所以:我想要的(如图所示)所有节点都在特定节点“上方”以及他们的孩子。

This should work: 这应该工作:

MATCH (red)<-[*]-(parent)-[*0..10]->(children)
WHERE red.id = xxx
RETURN parent, children

Find all of the parents of the red node and all children of the parents. 找到红色节点的所有父母和父母的所有孩子。

In general, a graph DB can have multiple disjoint subgraphs (which do not even have to be trees). 通常,图形DB可以具有多个不相交的子图(甚至不必是树)。 For example, suppose there are additional nodes that are not connected in any way to your subgraph. 例如,假设有其他节点未以任何方式连接到子图。

Here is one way you can get all nodes that are not connected to a specified node via forward REL relationships. 这是通过前向REL关系获得未连接到指定节点的所有节点的一种方法。 I assume that the interesting nodes all have the same label ( Foo ) and that there are other nodes without that label. 我假设有趣的节点都有相同的标签( Foo ),并且还有其他没有该标签的节点。

MATCH (n:Foo { id: 123 })-[:REL*]->(m:Foo)
WITH (COLLECT(DISTINCT m) + n) AS not_wanted
MATCH (x:Foo)
WHERE NOT x IN not_wanted
RETURN x;

Note: This query can take a very long time (or run out of memory), depending on big the "tree" rooted at n is and how many nodes there are in the DB. 注意:此查询可能需要很长时间(或耗尽内存),具体取决于以n为根的“树”以及数据库中有多少个节点。 You should omit the node labels that do not help you filter out anything. 您应该省略不帮助您过滤掉任何内容的节点标签。

Depends. 要看。 Assuming that all of your node labels are the same, this should work: 假设所有节点标签都相同,这应该有效:

   MATCH (a:circle)-[r]->(b:circle)
    WHERE a.colour <> 'Red' AND b.colour <> 'Red'
    RETURN a,b

暂无
暂无

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

相关问题 Neo4j Cypher Query 获取所有子节点,直到到达具有特定关系的节点 - Neo4j Cypher Query to get all sub nodes until reaching a node with a specific relationship Neo4j:检索连接到Neo4j Rest中的节点或通过Cypher的所有节点和关系 - Neo4j : Retrieving All Nodes and Relationship connected to a Node in Neo4j Rest OR through Cypher Neo4j Cypher Query:查找连接到一个节点且具有 3 个以上其他关系的所有节点 - Neo4j Cypher Query: Finding all nodes, that are connected to a node, that has more than 3 other relationships Neo4j 密码查询获取开始和结束节点之间的所有节点,包括 - Neo4j cypher query get all nodes between a start and end node including Neo4j Cypher 排除缺少特定关系的节点 - Neo4j Cypher exclude nodes where a specific relationship is missing 查找没有特定关系的节点(Cypher / neo4j) - Finding nodes that do not have specific relationship (Cypher/neo4j) 在 Neo4j 中如何返回特定节点或与密码的关系? - In neo4j how to return specific nodes or relationship with cypher? Neo4j密码查询:具有指定节点和关系属性的AllShortestPaths - Neo4j cypher query: AllShortestPaths with specified nodes and relationship properties Neo4j Cypher查询,用于查找具有关系的连接节点 - Neo4j Cypher query for finding connected nodes with a relationship Cypher (Neo4j) 创建与所有其他节点的关系(自身除外) - Cypher (Neo4j) create relationship to all other nodes (except itself)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM