Adding multiple labels when loading from CSV

(Norbert Preining) #1

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:, 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?

(Stefan Armbruster) #2

standard cypher does not allow for dynamic labels - this is basically what you want with :LABELS column.

CALL apoc.create.addLabels to the rescue!

(Michael Hunger) #3

you should only use the uuid for merging (and create an constraint on it).

There is also apoc.merge.node() which allows for dynamic labels too.

(Norbert Preining) #4

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.

Thanks a lot for your suggestions


(Stefan Armbruster) #5

apoc.merge.node allows you to supply two maps: on for identifying properties and another one for the remainder. What are you missing there?

(Norbert Preining) #6

apoc.merge.node ??? I cannot find this listed on which according to

All included procedures are listed in the overview in the documentation and detailed in subsequent sections.

Where can I find documentation for it.

Ahh, wait here it is mentioned that Summer 2017 Release of the APOC Procedures Library contains references to

CALL apoc.merge.node(['Label'], {id:uniqueValue}, {prop:value,...}) YIELD node;
CALL apoc.merge.relationship(startNode, 'RELTYPE', {[id:uniqueValue]}, {prop:value}, endNode) YIELD rel;

I will play with it, since there is no documentation but I guess I can guess what it does. Maybe update the documentation would be a good service ;-)

Thanks for the pointer!!!