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.

Reduce the number of relations in the appearance

2X_6_6f9d10191e6a2f43936f84bbab9058df1019bbc8.png
ex : I want to make only one relation "POSTED" outgoing from "NOREVIE" knowing that it ends up by having 4 relations after .

1 ACCEPTED SOLUTION

Like I said in my first answer, you need to use the pattern MATCH, MATCH, MERGE during your import.

So you should use this script instead :

LOAD CSV WITH HEADERS FROM 'file:///DOCO.csv' AS DonneursDordre
MATCH (do:DO {id: DonneursDordre.DO_ID}), 
      (c:Contrat {id: Contrats.Contrat_ID})
MERGE (do)-[:POSTED]->(c)

With this script, you will have only one relationship between a DO and a Contract, even if there are many lines in your csv.

Cheers

View solution in original post

6 REPLIES 6

Benoit
Graph Buddy

Can you give a little more context ?

For example how do you create your data in Neo4j ?
I assume it's via GraphQl, but what is your schema, what is your resolver for creating those relationship, ...

In Cypher to avoid this, you can use the Merge :

MATCH (start: ....)
MATCH (end: ....)
MERGE (start)-[:POSTED]->(end)

Well I just imported 5 csv files : DO , Contrat , Attrib , DOCO(in which I have DO/Contrat Rleationship )and COAT (in which I have Contrat/Attrib relationship) and I used those two queries for relationships :
Query 1 : DOCO :
LOAD CSV WITH HEADERS FROM 'file:///DOCO.csv' AS DonneursDordre
MATCH(do:DO {id: DonneursDordre.DO_ID}), (c:Contrat {id: Contrats.Contrat_ID})
CREATE (do)-[:POSTED]->(c)

Query 2 : COAT :
LOAD CSV WITH HEADERS FROM 'file:///COAT.csv' AS Contrats
MATCH (c:Contrat {id: Contrats.Contrat_ID}) , (at:Attrib {id: Contrats.Attrib_ID})
CREATE (c)-[:ASSIGNED]->(at)

Like I said in my first answer, you need to use the pattern MATCH, MATCH, MERGE during your import.

So you should use this script instead :

LOAD CSV WITH HEADERS FROM 'file:///DOCO.csv' AS DonneursDordre
MATCH (do:DO {id: DonneursDordre.DO_ID}), 
      (c:Contrat {id: Contrats.Contrat_ID})
MERGE (do)-[:POSTED]->(c)

With this script, you will have only one relationship between a DO and a Contract, even if there are many lines in your csv.

Cheers

Can I just update it without reloading ?
Thanks a lot !

Nop, you need to delete your database and to reload your scripts

Perfect ! Thanks a lot 🙂