I am using the line of code below to import a very simple csv file for testing. The data is imported, however, the properties are not. What could be the problem here? Any ideas?
/// My line of code
LOAD CSV WITH HEADERS FROM "file:///test1.csv" AS row
CREATE (n:naam {bedrijf:row.bedrijf})
CREATE (l:leeftijd)
CREATE (n)-[:IS]->(l);
///My csv file which is called test1
naam; bedrijf; leeftijd
Pietje Puk; Annechien; 28
Beste Shana,
You can add FIELDTERMINATOR ";" to your import line.
And to get a test sample of the data you want to import you can use RETURN row.bedrijf LIMIT 3.
And you can take a look at this tutorial:
Watch “1120 - Using Load CSV in the Real World” on Vimeo: 1120 - Using Load CSV in the Real World on Vimeo.
Try this:
LOAD CSV WITH HEADERS FROM "file:///test1.csv" AS row
CREATE (n:naam {bedrijf:row. bedrijf})
CREATE (l:leeftijd {leeftijd: row. leeftijd})
CREATE (n)-[:IS]->(l);
There is a blank space before second and third column headers. You have to include that blank space before 'bedrijf' and 'leeftijd'
Basically this. Your CSV file isn't formatted right, the spaces between the values result in the property keys being prefixed with a space, and with the property values also being prefixed with a space (excepting the first property key and value, since those don't have spaces before them in your CSV). Eliminate the spaces in your CSV following the semicolons and then it should import your data properly.
The trim function will work for the property values, yes, but the header line needs some fixing so that the property keys don't include leading whitespace.
Thanks to all the great advice below, my final solution was a combination of using the FIELDTERMINATOR clause and adjusted the raw CSV file so that there where no more spaces between the values.
Because I at first wanted to make my code as clean as possible, I wanted to change the separators from semicolon to comma in my settings. But I found that, because I am working on a Mac, this turns out to be quite a hassle. Therefore, the FIELDTERMINATOR clause was eventually part of my solution.
If the file is coming from a third party where the user has no control on the format and still wants to import data into Neo4j database what options the user has?
Really depends on the context, and where/how you're getting the file. If you're automating it, then I'd do my best to try to work with that third-party to get it in csv format, or convert it after downloading.
This is not a practical solution!
Check these links for practical solutions:
https://community.neo4j.com/t/trouble-with-split-and-unwind-syntax/28035/4
https://community.neo4j.com/t/many-to-many-relations-reading-from-csv-file/27743/5
I think a more practical solution to this approach would be to import the data from 1 or more CSVs in RDBMS system and then pull that data into a standard format that ETL tools supported by Neo4j can accept. The frequency and mechanism of Data Sync between RDBMS and Neo4j can be decided after a discussion with Solution Architects and Developers.