[英]Neo4j cypher query to find out connected nodes
I have given query like this 我给这样的查询
WITH ['1000Anthem.txt','1007AW.txt','100Art.txt'] as NDS
UNWIND RANGE(0, size(NDS)-2) as i
UNWIND RANGE(i+1, size(NDS)-1) as j
WITH NDS, NDS[i] as N1, NDS[j] as N2
MATCH path = (N1)-[*]-(N2)
WHERE length(path)+1 <=size(NDS)
AND ALL(n in nodes(path) WHERE n in NDS)
RETURN path
I got the following error 我收到以下错误
Type mismatch: N1 already defined with conflicting type String (expected Node) (line 2, column 15 (offset: 224)) "MATCH path = (N1)-[*]-(N2) WHERE length(path)+1 <=size(NDS) AND ALL(n in nodes(path) WHERE n in NDS) RETURN path"
类型不匹配:N1已经用冲突类型String(预期节点)(第2行,第15列(偏移量:224))定义了“ MATCH path =(N1)-[*]-(N2)WHERE length(path)+1 <=大小(NDS)和所有(节点(路径)中的n,在NDS中的n)返回路径”
Your N1 and N2 variables are bound to strings from your list. 您的N1和N2变量绑定到列表中的字符串。
The MATCH afterwards is attempting to use them as nodes, which isn't possible. 之后,MATCH尝试将它们用作节点,这是不可能的。 A string is not a node.
字符串不是节点。
If you want to lookup a node where one of its properties is equal to the string, you'll need a different approach, using different variables for the nodes, and a predicate in the WHERE clause to filter only nodes where the node's property is equal to the string. 如果要查找其属性之一与字符串相等的节点,则需要使用不同的方法,对节点使用不同的变量,并在WHERE子句中使用谓词以仅过滤节点属性相等的节点。到字符串。
EDIT 编辑
You haven't provided any context into what these nodes are supposed to be, no labels, and non-descriptive variable names, so I'm just going to make a wild guess and say these are nodes labeled :File, with the property name
. 您尚未提供有关这些节点应该是什么的上下文,没有标签,也没有提供非描述性的变量名,所以我将做出一个疯狂的猜测,并说这些是标记为:File的节点,其属性
name
。
Your lookup and collecting of the nodes at the start of the query would be something like: 您将在查询开始时查找并收集节点,如下所示:
WITH ['1000Anthem.txt','1007AW.txt','100Art.txt'] as NDS
MATCH (f:File)
WHERE f.name in NDS
WITH collect(f) as NDS
...
If you have an index on :File(name), then the index will be used to speed up that lookup. 如果您在:File(name)上有一个索引,则该索引将用于加快查找速度。 Your
NDS
variable at this point will be a collection of nodes instead of a collection of strings, so the remaining parts of your query will be syntactically correct. 此时的
NDS
变量将是节点的集合而不是字符串的集合,因此查询的其余部分在语法上是正确的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.