1

I'm trying to create nodes with one set label (:object) and two additional labels that are based on values in the following CSV file:

Object_ID Classification Hierarchy_name Object_type
O0010 visual_works sculpture sculpture
O0011 components book_jackets book

I thought it would be possible to add dynamic labels based on the values in the spreadsheet using the $ expression, but I cannot find information about how to use this in relation to loading information from a CSV file.

Currently, my faulty script looks like this:

LOAD CSV WITH HEADERS FROM 'file:///classification.csv' AS row
CREATE (o:object:$(row.Hierarchy_name):$(row.Classification){ID: row.Object_ID, Type: row.Type});

1 Answer 1

0

Dynamic labels in SET clauses was introduced in Neo4j 5.24, so you must upgrade to that version at a minimum.

LOAD CSV WITH HEADERS 
FROM 'file:///classification.csv' AS row
CREATE (o:Object {ID: row.Object_ID, Type: row.Type})
SET o:$(row.`Hierarchy_name`)
SET o:$(row.`Classification`);
Sign up to request clarification or add additional context in comments.

1 Comment

Works as a charm, thanks a lot!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.