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 计算属性值,同时返回节点集合:
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 Cypher:
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屋!