I've been fighting with this very simple task all day. I have read countless help files, tips, manual entries, watched videos -- about to pull out my hair.
I have a very simple csv (countries.csv) with the following columns: [ name, alpha2, alpha3, region, subRegion ]
I want my node to have the name of the country as the label. For example: (Australia). I want the other columns to be properties of that label.
Whenever I load the csv I either get nodes that don't have a label (blank) or use the alpha2 (AU) as the label.
Please help figure out a simple, repeatable method to load csv files so I know how to label them with one column and use the other columns as properties.
Thanks,
John
Here is a sample of my last run:
load csv with headers from "file:///countries.csv" as row create (c:Country) set c = row {.name, alpha2:row.alpha2, alpha3:row.alpha3, region:coalesce(row.region, "Unknown"), subRegion:coalesce(row.subRegion,"Unknown")}```
I went back to the basics and read more about CREATE. I thought I figured it out with the code below but the nodes came back blank again. I do see all of the properties when I click on one but I expected each node to have the name of the country on it.
load csv with headers from "file:///countries.csv" as row
CREATE (c:Country {name:row.name, alpha2:row.alpha2, alpaha3:row.alpha3, region:coalesce(row.region, "Unknown"), subRegion:coalesce(row.subRegion,"Unknown")})
Thanks for sharing the data. Looks like your .csv file is 'tab' separated and not comma separated.
Here is the Cypher:
load csv with headers from "file:///countries.csv" as row
FIELDTERMINATOR '\t'
MERGE (c:Country {name:row.name, alpha2:row.alpha2, alpaha3:row.alpha3, region:coalesce(row.region, "Unknown"), subRegion:coalesce(row.subRegion,"Unknown")})
For a problem like this, I'd use a text editor (VSCode on Linux, Notepad++ on windows, whatever) to extract the header and no more than two or three records from the desired input file. Give it a name like "tiny_countries.csv".
Then paste your code into the browser and use file:///tiny_countries.csv. The Neo4J browser is pretty good at prompting you (with squiggles) for things that confuse it and for syntax errors and typos.
Once you get it working on a tiny file, you'll almost certainly want to prefix your cypher with:
USING PERIODIC COMMIT 100 ...
This will break the ingest into smaller transactions (100 records in the above) so that you avoid memory issues during the ingest. I prefer the Neo4J practice of using all caps for the Cypher elements so that they stand out from names and such that I create.
If you haven't already, I suggest adding indices and constraints before doing an ingest like this. It makes an ENORMOUS difference in ingest performance.