简体   繁体   English

获取 neo4j 中具有特定标签的节点

[英]Get the nodes with specific labels in neo4j

I want to get all the nodes that have specific labels.我想获取所有具有特定标签的节点。 My code:我的代码:

match (n) where labels(n)=["Person","Actor","Old"] return n

While there are nodes that satisfy this property I do not get any results.虽然有满足此属性的节点,但我没有得到任何结果。

This is why:这就是为什么:

Labels(n) returns an array of strings, but not necessarily in a specific order. Labels(n) 返回一个字符串数组,但不一定按特定顺序。

You can try this:你可以试试这个:

WHERE n:Person AND n:Actor AND n:Old

Or或者

WHERE ALL(l in [“Person”, “Actor”, “Old”] WHERE l IN labels(n) )

List does not match if the items are not in the same order/sequence.如果项目的顺序/顺序不同,则列表不匹配。 So first of all, list out all labels in your database so you can see how the labels are arranged.因此,首先,列出数据库中的所有标签,以便查看标签的排列方式。

match (n) 
return distinct labels(n)

Then you will see which node will have those labels that you look for: ["Person","Actor","Old"].然后您将看到哪个节点将具有您要查找的标签:["Person","Actor","Old"]。

If you are trying to find nodes where it contains all nodes in that list in any order then this query will work for you.如果您试图以任何顺序查找包含该列表中所有节点的节点,那么此查询将为您工作。

match (n) 
where all(lbl in ["Person","Actor","Old"] where lbl in labels(n))
return n

if you like using APOC functions, here is the query如果你喜欢使用 APOC 函数,这里是查询

match (n)
where apoc.coll.isEqualCollection(["Person","Actor","Old"], labels(n))
return n

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM