cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Import Relationships with Properties

I'm finally getting somewhere. I have the following nodes:

  • (Country), (Employee), (Language), (Specialty)


    I have the following relationships:

  • (employee)-[:LIVES_IN]->(country)
  • (employee)-[:SPECIALIZES_IN]->(specialty)

I now want to add a relationship with a property:

  • (employee)->[:SPEAKS]->(language)

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

6 REPLIES 6

Bennu
Graph Fellow

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

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!

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

Thanks for all of your help so far. I tried the above -- it looked like it should have worked but it failed here:




Is that because the Language Node does not have a langLevel property already? If so, that doesn't make sense to me. I basically have Frence, English, Spanish, etc. with associated IDs. I now want to show that employee; John Doe speaks French - at level 2 (for example).

Hi!

My bad, I forgot to include row on the WITH instruction. check the edited post.

H

Thanks so much! I'm learning a lot. I appreciate your time and patience!