我想在neo4j数据库中找到每个类型的所有重复节点
示例:我有node1,其属性为:name、adress、phone如果不在查询中指定属性名称,我不想匹配所有重复的节点
你也可以试试这个:
Match (n1:Person)
Match (n2:Person) Where id(n1) <> id(n2) and properties(n1)=properties(n2)
RETURN n1, n2
要忽略某些属性,请尝试以下操作:
WITH ['author', 'location', 'traceId'] AS ignoredProperties
Match (n1:Person)
Match (n2:Person) Where id(n1) <> id(n2) and ALL(x IN keys(properties(n1)) WHERE x IN ignoredProperties OR n1[x] = n2[x])
RETURN n1, n2
首先检查所有属性是否相同,然后检查所有值是否相同。
//check that all keys in n1 and n2 are the same
Match (n1:Person)
Match (n2:Person) Where n1 < n2 and keys(n1)=keys(n2)
//check that all properties are the same in n1 and n2
WITH n1, n2, [ k1 in keys(n1) | n1[k1] ] as n1_props, [ k2 in keys(n2) | n2[k2] ] as n2_props
Where n1_props = n2_props
RETURN n1, n2
也许只是分组并计数:
match (p:Person)
with p.name as name,
p.adress as address,
p.phone as phone,
count(*) as cnt
where cnt > 1
match (p:Person{name: name, address: address, phone:phone})
return p