Importing a thesaurus from CSVs

Hello! Thanks for your patience and help. It's end of the day Friday, and I'm just tired, so I'm going to ask for help. I'm trying to import a relatively straightforward thesaurus into a graph. I've organized the information into two CSVs (pipe delimited), one for the nodes and one for the relationships.

nodes.csv has a structure like this:
:ID | concept:string
1 | foo
2 | bar
3 | spam
4 | ham

relationships.csv has this structure like this:
1 | is_not | 2
1 | is_not |3
3 | is_like | 4

Now, when I try to import this, I'm using these queries:

CREATE INDEX ON :Concept(name)

LOAD CSV WITH HEADERS FROM "file:///nodes.csv" AS csvLine fieldterminator '|'
CREATE (c:Concept {id: toInteger(,})

LOAD CSV WITH HEADERS FROM "file:///relationships.csv" AS csvLine FIELDTERMINATOR "|"
MATCH (concept:Concept {id: toInteger(csvLine.conceptID)}),(concept:Concept {id:toInteger(csvLine.conceptID)})
CREATE (concept)-[:RELATIONSHIP {type: csvLine.type}]->(concept)

I end up with a lot of blank nodes, and no relationships. What am I doing wrong?

In your CSV file your header is called :ID and :START_ID, and in your cypher you're referring to it as and csvLine.conceptID which don't exist in your input CSV. So they are null. So you get blank nodes. ;)

You need instead to do something like this:

LOAD CSV WITH HEADERS FROM "file:///nodes.csv" AS csvLine fieldterminator '|'
CREATE (c:Concept {id: toInteger(csvLine.`:ID`), name:csvLine.`concept:string`})

In other words, match up your column metadata. Notice the backticks I'm using around the column names, this is so that you can include characters like : in a property name in Neo4j.

Hi David, thank you very much, this worked for me!

1 Like