Label Duplication

I'm having a customers data base with mobile numbers

each customer mobile number to number has called connection(They have called each other)

the relation of the customer data base can be seen and taken from the call log data base (Which customer has called to another customer a_number HAS CALLED b_number)

so i imported the call log data base assining to customer data base numbers


load csv with headers from 'file:///calldeta.csv' as line

MERGE (n:Customer{mob:line.a_number})-[:CALLED{duration:line.duration}]->(m:Customer{mob:line.b_number})

the problem is it creates multiple lables which duplicates the same number example if

071111 CALLED 07222 then the 2 labels will be created

but if 07111 CALLED 07333 the it creates again a 07111 lable & joins to 07333

I want to make a join from the earlier relaion 07111 CALLED 07222 without make another 07111 label again I want to join from the created 0711 label to 07333

So i can see that 07111 & 07222 & 077333 all have a common connection

Hi, MERGE is looking for that entire pattern. As it did not find the entire pattern, the whole pattern is created and that's why you get duplicate nodes.

I suggest read:

For your query, try:

load csv with headers from 'file:///calldeta.csv' as line

MERGE (n:Customer{mob:line.a_number})
MERGE (m:Customer{mob:line.b_number})
MERGE (n)-[:CALLED{duration:line.duration}]->(m)
1 Like


If you are loading the nodes then try the method provided by @paulare.
However if you already have node placed in the system and want to merge them then try
MATCH (m:Customer)
WITH m.mob as mob, collect(m) as nodes
CALL apoc.refactor.mergeNodes(nodes, {properties: "combine"}) YIELD node
RETURN node;

1 Like

Sir after implementing your code it appeared like this

Check your data and look for any comma in any column values. If you can post some sam please data that would be helpful.

1 Like