How to avoid duplicate and to create relationship dynamically in neo4j with csv data

29 views
Skip to first unread message

Ganesh Babu

unread,
Jul 6, 2018, 6:39:01 AM7/6/18
to Neo4j

Hi All,

 

I am trying to build graph with the following csv data using cypher query,

 

Name,Team

ganesh
,misra

jayakumar
,misra

misra
,vinoth

vinoth
,ganesh

chinmaya
,mano

mano
,darga


 

Below is the cypher query I tried,

 

LOAD CSV WITH HEADERS FROM "file:///dummy.csv" AS csvLine

MERGE
(team:Team {Team: csvLine.Team})

CREATE
(name:Name {Name: csvLine.Name})

CREATE
(name)-[:WORKING_WITH]->(team)



Below is the response that I got in neo4j browser,






I want to remove the duplicate name in the graph and to create relationship dynamically and it should be connected with each other based on the data. Below is the expected graph I am looking for it. How to achieve this using cypher query?


Please let me know your thoughts and please correct me if I am doing anything wrong in the cypher query.





Thanks,
Ganeshbabu R


Russ Burkert

unread,
Jul 6, 2018, 9:35:55 AM7/6/18
to ne...@googlegroups.com

Ganesh

Just change the Create to Merge and I think you will get the results you need

--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael Hunger

unread,
Jul 6, 2018, 10:23:44 AM7/6/18
to ne...@googlegroups.com
I think there is some confusion in your data, it's not really Person and team but person works with person.

LOAD CSV WITH HEADERS FROM "file:///dummy.csv"
 AS csvLine

MERGE 
(p1:Person {name: csvLine.Team}) 

MERGE 
(p2:Person {name: csvLine.Name}) 

MERGE 
(name)-[:WORKING_WITH]-(team)


To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+unsubscribe@googlegroups.com.

Kamal Murthy

unread,
Jul 7, 2018, 3:23:25 PM7/7/18
to Neo4j
The last MERGE statement should be like this:

MERGE (p1:Person {name: csvLine.Team}) 

MERGE 
(p2:Person {name: csvLine.Name}) 

MERGE (p2)-[:WORKING_WITH]-(p1)

-Kamal

Ganesh Babu

unread,
Jul 13, 2018, 1:04:41 AM7/13/18
to Neo4j
I tried with your suggestions and it worked as expected.

Thanks for your response.


- Ganesh
Reply all
Reply to author
Forward
0 new messages