When using the neo4j-admin tool I can attach multiple labels to a node by using the :LABELS column. I want to do something similar with LOAD CSV and thought that a statement like:
LOAD CSV WITH HEADERS FROM "file:///tlpdb/48871/outnew/node-TLPackage.csv" AS row
MERGE (c:TLPackage { uuid: row.uuid, name: row.name, revision: toInt(row.revision) })
ON CREATE set c:row.`:LABELS`
might work, but that didn't do it. Is there a way to use the labels taken from a column (in my case there is only one additional label there) and add it to the load/merge/on create call?
Hi Stefan, hi Michael,
thanks for suggestion apoc functions, which I have tried, but it seems that in the ON CREATE part of the MERGE command calls are not allowed. That would mean I would have to add additional calls after the initial merge to rewrite labels I guess.
Since I have only 6 or so sub-classes (different labels to add) I have changed the approach, split the original data into separate csv files per label, and then just add one cypher merge call for each csv separately.
This is not optimal, because it codes parts of the logic into the cypher code, while having programmatically being able to add labels from CSV columns would be future proof.
I was having this same exact problem, but apoc.merge.node did not solve my issue. I read the docs on this apoc statement, and it was not clear to me how to add multiple labels to only those nodes that are created with the MERGE + ON CREATE SET piece.
My question is: using MERGE ON CREATE SET, how can I add more labels only to those nodes that are created during the MERGE execution?
This is what gave me the result I was looking for:
LOAD CSV WITH HEADERS
FROM "file:///file.csv" AS row
MERGE(p:Person {id: row.id})
ON CREATE
SET p:New,
p.name = row.name,
p.role = row.role,
p.location = row.location
I do this because this statement helps me add new nodes to my database. With the "New" label on these nodes, I can easily query these nodes to just focus on these to create the new relationships to the other nodes on the graph.
Is there a better way to do this with apoc.merge.node?