Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
01-31-2020 05:33 PM
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:
:START_ID | :TYPE | :END_ID
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 CONSTRAINT ON (concept:Concept) ASSERT concept.id IS UNIQUE
CREATE INDEX ON :Concept(name)
LOAD CSV WITH HEADERS FROM "file:///nodes.csv" AS csvLine fieldterminator '|'
CREATE (c:Concept {id: toInteger(csvLine.id), name:csvLine.name})
USING PERIODIC COMMIT 500
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?
Solved! Go to Solution.
02-01-2020 05:20 AM
In your CSV file your header is called :ID
and :START_ID
, and in your cypher you're referring to it as csvLine.id
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.
02-01-2020 05:20 AM
In your CSV file your header is called :ID
and :START_ID
, and in your cypher you're referring to it as csvLine.id
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.
02-03-2020 05:41 PM
Hi David, thank you very much, this worked for me!
All the sessions of the conference are now available online