How to fuse same nodes

Hello, I have a problem :

I'm working on a Graph with Countries of the world
I use this Cypher command :

LOAD CSV WITH HEADERS FROM "file:///test.csv" AS line
create (cap:Capitale {name: line.capital})
create (p:Pays {name: line.pays, population: line.population, superficie: line.superficie, pib: line.pib })
create (cont:Continent {name: line.continent})
create (o:Ocean {name: line.ocean})
create (i:Iles {name: line.iles})	
create (org:Organisme {name: line.organisme})
create (langPrinc:LanguePrincipale {name: line.languePrincipale})
create (langSec:LangueSecondaire {name: line.autreLangue})
create (d:Dirigeant {name: line.dirigeant, sexe: line.sexe})
create (gouv:Gouvernance {name: line.gouvernance})
create (m:Monnaie {name: line.monnaie})
create (dev:Devise {name: line.devise})


create (cap)-[:CAPITALE_DE]->(p)
create (langPrinc)-[:SPOKE]->(p)
create (langSec)-[:LANGUES_SECONDAIRES_PARLEE]->(p)
create (o)-[:BORDE]->(p)
create (p)-[:POSSEDE]->(i)
create (d)-[:DIRIGE]->(p)
create (m)-[:EST_LA_MONNAIE]->(p)
create (dev)-[:EST_LA_DEVISE]->(p)
create (p)-[:EST_SUR_CONTINENT]->(cont)
create (p)-[:TYPE_DE_GOUVERNANCE]->(gouv)
create (dir)-[:MEMBRE_DE]->(org) 
create (gouv)-[:SIEGE_A]->(cap)

When i start a Query to find all countries which speak english, I use this query : (Country)-[SPOKE]->(English)

The problem is : instead of creating one node with the langage ( here english ), and all the countries which speak this language around, it creates me tons of "english" node, each one linked to only one country

I use an CSV file to organise my data. And i already try to remplace all my CREATE by MERGE but i have an error : Neo.ClientError.Statement.SemanticError: Cannot merge node using null property value for name.

So i'm really stuck,
Thank for your help , I'm not english, if you need more distinct info, I can try again to explain

You definitely should use MERGE to create the relationships and ideally the nodes also, this will prevent duplicates.

From the error you are seeing, there is data in your CSV file that has no value for name. This is not allowed in a MERGE. Can you clean up the data?

Ideally, you want uniqueness constraints on all of the properties you are using the create the nodes.

Elaine

2 Likes

Your test.csv file has null/no data for one or more columns on any row. There are two ways to handle this.

  1. If you do not want import the whole row with column(s) with null/no data then:
    Example: line.pays has no value and you want to skip this row

LOAD CSV WITH HEADERS FROM "file:///test.csv" AS line
WITH line WHERE line.pays is NOT NULL

MERGE (cap:Capitale {name: line.capital}).......
MERGE (gouv)-[:SIEGE_A]->(cap)

  1. If you want to include rows with some null value columns then
    Example: line.languePrincipale = ""

LOAD CSV WITH HEADERS FROM "file:///test.csv" AS line
WITH line

MERGE (cap:Capitale {name: line.capital})
MERGE (p:Pays {name: line.pays, population: line.population, superficie: line.superficie, pib: line.pib })
MERGE (cont:Continent {name: line.continent})
MERGE (o:Ocean {name: line.ocean})
MERGE (i:Iles {name: line.iles})
MERGE (org:Organisme {name: line.organisme})

// when line.languePrincipale has some value......

FOREACH(ignoreMe IN CASE WHEN line.languePrincipale IS NOT NULL THEN [1] ELSE END |

MERGE (langPrinc:LanguePrincipale {name: line.languePrincipale})
MERGE (langPrinc)-[:SPOKE]->(p)

)

// when line.languePrincipale has no value...... NA (Not Available). Use this if you want to create language node with NA value.

FOREACH(ignoreMe IN CASE WHEN line.languePrincipale IS NULL THEN [1] ELSE END |

MERGE (langPrinc:LanguePrincipale {name: "NA"})
MERGE (langPrinc)-[:SPOKE]->(p)

)

MERGE (langSec:LangueSecondaire {name: line.autreLangue})
MERGE (d:Dirigeant {name: line.dirigeant, sexe: line.sexe})
MERGE (gouv:Gouvernance {name: line.gouvernance})
MERGE (m:Monnaie {name: line.monnaie})
MERGE (dev:Devise {name: line.devise})

MERGE (cap)-[:CAPITALE_DE]->(p)
MERGE (langPrinc)-[:SPOKE]->(p)
MERGE (langSec)-[:LANGUES_SECONDAIRES_PARLEE]->(p)
MERGE (o)-[:BORDE]->(p)
MERGE (p)-[:POSSEDE]->(i)
MERGE (d)-[:DIRIGE]->(p)
MERGE (m)-[:EST_LA_MONNAIE]->(p)
MERGE (dev)-[:EST_LA_DEVISE]->(p)
MERGE (p)-[:EST_SUR_CONTINENT]->(cont)
MERGE (p)-[:TYPE_DE_GOUVERNANCE]->(gouv)
MERGE (dir)-[:MEMBRE_DE]->(org)
MERGE (gouv)-[:SIEGE_A]->(cap);

Thank a lot you solve my problem !