neo4j查找具有匹配属性的所有节点 [英] neo4j find all nodes with matching properties
问题描述
我有一个相对较大的节点集,并且我想查找所有具有匹配属性值的节点对,但是我不知道或事先不在意什么是属性值.这基本上是尝试查找重复的节点,但是我可以将重复的定义限制为具有相同属性值的两个或多个节点.
I have a relatively large set of nodes, and I want to find all pairs of nodes that have matching property values, but I don't know or care in advance what the property value is. This is basically an attempt to find duplicate nodes, but I can limit the definition of a duplicate to two or more nodes that have the same property value.
任何想法如何进行?在neo4j文档中找不到任何起点.我正在使用1.8.2社区版.
Any ideas how to proceed? Not finding any starting points in the neo4j docs. I'm on 1.8.2 community edition.
编辑
抱歉,在最初的问题中不清楚,但我正在谈论通过Cypher进行此操作.
EDIT
Sorry for not being clear in the initial question, but I'm talking about doing this through Cypher.
推荐答案
通过密码对属性值进行计数,并返回节点的集合:
Cypher to count values on a property, returning a collection of nodes as well:
start n=node(*)
where has(n.prop)
with n.prop as prop, collect(n) as nodelist, count(*) as count
where count > 1
return prop, nodelist, count;
控制台示例: http://console.neo4j.org/r/k2s7aa
您也可以像这样使用属性进行索引扫描(以避免查看不具有此属性的节点):
start n=node:node_auto_index('prop:*') ...
You can also do an index scan with the property like so (to avoid looking at nodes that don't have this property):
start n=node:node_auto_index('prop:*') ...
2.0带有标签标签的密码:
2.0 Cypher with a label Label:
match (n:Label)
with n.prop as prop, collect(n) as nodelist, count(*) as count
where count > 1
return prop, nodelist, count;
3.x的更新:has
被exists
取代.
Update for 3.x: has
was replaced by exists
.
这篇关于neo4j查找具有匹配属性的所有节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!