When I search for nodes with a certain zipcode:
MATCH (z:ZipCode) WHERE z.zipcode = "2014 AAE" RETURN z.zipcode
I get duplicates:
z.zipcode
2014 AAE
2014 AAE
When I search for relations of a certain zipcode:
MATCH p=(z:ZipCode)-->() WHERE z.zipcode = "2014 AAE" RETURN p
I get a single zipcode node 2014 AAE
pointing to a house node 518Q
How can I merge the zipcode nodes with the same property value, but leave all the relations intact of the zipcode?
Edit:
After cybersam's answer I constructed a query. Is this the way to combine the nodes with APOC?
MATCH (z1:ZipCode)-->(), (z2:ZipCode)-->()
WHERE z1.zipcode = z2.zipcode
AND ID(z1) <> ID(z2)
WITH COLLECT([z1,z2]) AS zs
CALL apoc.refactor.mergeNodes(zs) YIELD node
RETURN node;
I get this as error:
Type mismatch: expected Collection<Node> but was Collection<Collection<Node>> (line 5, column 31 (offset: 160))
"CALL apoc.refactor.mergeNodes(zs) YIELD node"
ZipCode
. Is it possible that there is also some nodep
with zipcode2014 AAE
which has"IN-relation"
? I mean(z:ZipCode)<--()
. Try to rewrite your second query to check it. But It is long time that I played with neo4j so maybe my thoughts are wrong. – Gondilm
andn
), compare them so you know they are same (have same propertiesm.zipcode = n.zipcode
) but they are not same one nodem<>n
, than you have to find all relationships ofn
which are not inm
, create these "n-relationships" on nodem
and finally deletenode n and all it's relationships
. Better solution would be make a good create queries so you merge duplicates during creating nodes and relationships and you don't have to do it later. – Gondil