如何使用where子句在Neo4j中查找特定的子图 [英] How to find specific subgraph in Neo4j using where clause

查看:895
本文介绍了如何使用where子句在Neo4j中查找特定的子图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大图,其中一些关系具有一些属性,在创建子图时要使用这些属性有效地修剪该图.例如,如果我有一个名为'relevance score'的属性,并且我想从一个节点开始扩展,则收集所有节点和关系,但是在关系具有上述属性的任何地方都进行修剪.

I have a large graph where some of the relationships have properties that I want to use to effectively prune the graph as I create a subgraph. For example, if I have a property called 'relevance score' and I want to start at one node and sprawl out, collecting all nodes and relationships but pruning wherever a relationship has the above property.

我这样做的意图是使该查询成为了网络

My attempt to do so netted this query:

start n=node(15) match (n)-[r*]->(x) WHERE NOT HAS(r.relevance_score) return x, r

我的尝试有两个无法解决的问题:

My attempt has two issues I cannot resolve:

1)反思我相信这不会导致修剪的图,而是会导致不相交的图的集合.另外:

1) Reflecting I believe this will not result in a pruned graph but rather a collection of disjoint graphs. Additionally:

2)我从看起来正确的密码查询中收到以下错误:

2) I am getting the following error from what looks to be a correctly formed cypher query:

Type mismatch: expected Any, Map, Node or Relationship but was Collection<Relationship> (line 1, column 52 (offset: 51))
"start n=node(15) match (n)-[r*]->(x) WHERE NOT HAS(r.relevance_score) return x, r"

推荐答案

您应该能够在关系集合上使用ALL()函数对路径中的所有关系强制使用该属性,该属性为null.

You should be able to use the ALL() function on the collection of relationships to enforce that for all relationships in the path, the property in question is null.

使用Gabor的样本图,此查询应该可以正常工作.

Using Gabor's sample graph, this query should work.

MATCH p = (n {name: 'n1'})-[rs1*]->()
WHERE ALL(rel in rs1 WHERE rel.relevance_score is null)
RETURN p

这篇关于如何使用where子句在Neo4j中查找特定的子图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆