Load csv with dublicated nodes where nodes should be unique

Hi everyone,
I try to load csv file into the neo4j.
My Query is:

LOAD CSV WITH HEADERS FROM "file:///C:/mesh_network.csv" AS line
Merge(n:Mesh {name:line.mesh,frequency:toInteger(line.frequency1)})
Merge(m:Mesh {name:line.mesh,frequency:toInteger(line.frequency2)})
Merge (n)-[:SEEN {weight:toInteger(line.weight)}]-(m)

Before loading data I set node should be unique based on node name.

However, it gives this error.

Hi @dilmacfatih

Did you create CONSTRAINT like this?

CREATE CONSTRAINT constraint_name ON (mesh:Mesh) ASSERT mesh.name IS UNIQUE



And DROP it.

DROP CONSTRAINT constraint_name

Thank you koji for your answer. Before loading the data i created constraint as you mentioned.
Without constraint it works. However i rellay want to single node for each mesh. That is why i created unique constraint. Otherwise the graph becames disconnected likte this.

Instead of 2 mesh1 in the graph there should be only 1.

mesh1 freq1 mesh2 freq2 weight
adult;15320;tranexamic acid;7;1
adult;15320;mediation analysis;7;3
adult;15320;hospitals special;59;22
adult;15320;vitamin d;283;37
adult;15320;bathroom equipment;10;2
adult;15320;otitis externa;1;1
adult;15320;health occupations;30;1
adult;15320;mediastinal emphysema;63;1
this is a pice of my dataset

Thank you again.

Hi @dilmacfatih

If your Mesh is unique by name, and you need Freq data, how about the following design?

1 Like

Hi , i checked number of unique mesh for both mesh1 and mesh2. Then i realized that the number of mesh2 more than number of mesh1. Then i picked up mesh2 as a first node and mesh1 for second node then it worked even wiht unique constraint.
Thank you again

1 Like