5

This example is taken from https://neo4j.com/developer/guide-importing-data-and-etl/#_importing_the_data_using_cypher"

LOAD CSV WITH HEADERS FROM "file:customers.csv" AS row
    CREATE (:Customer {companyName: row.CompanyName, customerID: row.CustomerID, fax: row.Fax, phone: row.Phone});

What I want to do is use a field in the CSV file to define the label in the node. For example:

LOAD CSV WITH HEADERS FROM "FILE:///Neo4j_AttributeProvenance.csv" AS CSVLine CREATE (q:CSVLine.NodeType { NodeID:CSVLine.NodeID, SchemaName:CSVLine.SchemaName, TableName:CSVLine.TableName, DataType:CSVLine.DataType, PreviousNodeID:CSVLine.PreviousNodeID });

Here is the error I get:

nicomp
  • 4,344
  • 4
  • 27
  • 60
  • Possible duplicate of [Neo4j Cypher - creating nodes and setting labels with LOAD CSV](https://stackoverflow.com/questions/24992977/neo4j-cypher-creating-nodes-and-setting-labels-with-load-csv) – Lucas Lima Aug 12 '19 at 07:12

1 Answers1

5

You should have a look at the APOC procedures. In this case there's a procedure able to create nodes dinamically based on column values in your .csv file. The syntax is:

CALL apoc.create.node(['Label'], {key:value,…​})

In your case the simplest syntax should be:

CALL apoc.create.node(["' + CSVLine.NodeType + '"], {NodeID: "' + NodeID:CSVLine.NodeID + '", etc}) yield node
Fabio Lamanna
  • 20,504
  • 24
  • 90
  • 122
  • The jar file goes in the plugins folder of the current DB, but otherwise it seems to work. Awesome. – nicomp Jul 18 '17 at 13:09
  • 1
    Yes sure, to install the apoc you need to put the .jar files into the plugins folder in your neo4j installation path. – Fabio Lamanna Jul 18 '17 at 13:10