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.

Create relationships from CSV dataset

Hi

We've created nodes such as p:Person for around 50 persons in a CSV file and what we currently want is to split up the property of lets say Company to create their own nodes for this, and make relationships between.

The current dataset (CSV) looks like:

First Name,Last Name,Email Address,Company,Position,Connected On
Kasper,Knudsen,,ABBA The Museum,Customer Service,06 May 2020
Casper,Knudson,,Zaplify,Co-Founder and CEO,21 Mar 2020

and we are executing with:

await session.run("MATCH (n) DETACH DELETE n")
await session.run("LOAD CSV WITH HEADERS FROM 'file:///Users/kasperknudsen/test/api/src/uploads/Connections.csv' AS csvLine CREATE(p:Person{emailid:csvLine.`Email Address`}) Set p.firstName=csvLine.`First Name`,p.lastName=csvLine.`Last Name`,p.company=csvLine.Company,p.position=csvLine.Position,p.connectedOn=csvLine.`Connected On`");

TLDR: So I guess we want to split up some properties and create company as their own nodes. The relationships should be between company, position and person to begin with, with relations such as: Company -> Position -> Person

7 REPLIES 7

intouch_vivek
Graph Steward

Hi @kasperknudz,

  1. Are you saying Person node already there in the DB and you to split it's property to distinct node of label Company ?

  2. Or you need to insert new dataset with Labels Person , Company and Position? If this is the case what is the relationship between these nodes? What will be properties of Nodes and relationships?

  3. Your data set has no email address and you are using that in the Create Statement

Hi @intouch.vivek,

  1. Well I am creating p:Person and actually created c:Company aswell now (for all companies as properties), and made relationships now so that is quite good.

  2. Well problem right now is that I still have duplicates (like relationships between person - company both ways + themselves..) so working on getting rid with those as of current.

  3. Ah yea I know very few has a email connected so will change that. What is shown is a small part of the dataset.

The updated code:

        await session.run("MATCH (n) DETACH DELETE n")
        await session.run("CREATE (you:Person {name:'You'})")
        await session.run("LOAD CSV WITH HEADERS FROM 'file:///Users/kasperknudsen/test/api/src/uploads/Connections.csv' AS csvLine CREATE(p:Person{emailid:csvLine.`Email Address`}) Set p.firstName=csvLine.`First Name`,p.lastName=csvLine.`Last Name`,p.company=csvLine.Company,p.position=csvLine.Position,p.connectedOn=csvLine.`Connected On`");
        await session.run("LOAD CSV WITH HEADERS FROM 'file:///Users/kasperknudsen/test/api/src/uploads/Connections.csv' AS row CREATE(c:Company) Set c.company=row.Company")
        await session.run("MATCH (c), (p) WHERE c.company=p.company MERGE (c)-[r:WORKSAT]->(p)")
        await session.run("match (c)-[r]->(p) with c,p,type(r) as typ, tail(collect(r)) as coll foreach(x in coll | delete x)")

Hey @kasperknudz,

I did not understand the Model.
And by seeing your code I suspect things are not in place.

Either explain the model and requirement or share your skype id we can discuss on the same

Hi @intouch.vivek

Add kappanskyper on Skype, and thanks a lot for your efforts with helping us on this project!
Will be busy today if you are wondering why I don't respond.

No worries, if you are occupied today, we will discuss tomorrow.

Hi @intouch.vivek

Can you add me on Skype if you are available or send me ur Skype-id?

Thanks, Kasper

My skype id is vksrivas_1978