Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
08-19-2021 11:05 AM
I'm finally getting somewhere. I have the following nodes:
I now want to add a relationship with a property:
but I want to add: a level {1,2,3,4,5} and I have the relationship csv with:
{
"langLevel": "2",
"languageID": "35",
"employeeID": "6800-1"
}
This is what I tried:
LOAD CSV WITH HEADERS FROM "file:///languagerel.csv" AS row
MERGE (employee:Employee {employeeID:coalesce(row.employeeID, "None")})
MERGE (language:Language {languageID:row.languageID})
MERGE (employee)-[:SPEAKS]->(language {langLevel:row.langLevel})
But that didn't work.
Sample from employees.csv
employeeID,last,first,name
6063-2,Miller,Anna,Anna Miller
6800-2,Page,Arline,Arline Page
Sample from languages.csv
languageID,lname
1,Mandarin Chinese
2,Spanish
3,Hindi
Sample from language relationships csv
employeeID,languageID,langLevel
6800-1,2,2
6063-1,1,1
I appreciate any help you can give. I am presenting a demo to our CEO tomorrow on NEO4J and how it can help our non-profit.
John
08-19-2021 11:57 AM
Hi @junknstuff777 !
Important question... Are you planning to create one Language node per Level? Otherwise may be better just adding the level condition into the relation.
LOAD CSV WITH HEADERS FROM "file:///languagerel.csv" AS row
MERGE (employee:Employee {employeeID:coalesce(row.employeeID, "None")})
MERGE (language:Language {languageID:row.languageID})
MERGE (employee)-[:SPEAKS {langLevel:row.langLevel}]->(language)
or
LOAD CSV WITH HEADERS FROM "file:///languagerel.csv" AS row
MERGE (employee:Employee {employeeID:coalesce(row.employeeID, "None")})
MERGE (language:Language {languageID:row.languageID, langLevel:row.langLevel})
MERGE (employee)-[:SPEAKS ]->(language)
Lemme know if one of the 2 suits your intentions.
H
08-19-2021 12:18 PM
No, I only have a language node with language name and language ID. I'm trying to figure out how to add the level condition to the relationship on import.
Again, my relationship.csv has: {langLevel:value, languageID:value, employeeID:value}
Thanks!
08-19-2021 12:25 PM
Hi @junknstuff777 !
Oh wait,
I assume you already load employees and languages. So it should something like:
LOAD CSV WITH HEADERS FROM "file:///languagerel.csv" AS row
MATCH (employee:Employee {employeeID:row.employeeID})
WITH employee, row
MATCH (language:Language {languageID:row.languageID})
WITH language, employee, row
MERGE (employee)-[:SPEAKS {langLevel:row.langLevel}]->(language)
If you have a lot of employee records, you should consider adding an Index on employeeID.
You should also think about what you really wanna do with employee rows without and employeeID. Otherwise you may end with a lot of records merged in one single None Employee.
H
08-19-2021 12:39 PM
Thanks for all of your help so far. I tried the above -- it looked like it should have worked but it failed here:
08-19-2021 12:41 PM
Hi!
My bad, I forgot to include row on the WITH instruction. check the edited post.
H
08-19-2021 12:44 PM
Thanks so much! I'm learning a lot. I appreciate your time and patience!
All the sessions of the conference are now available online