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.

Duplicated relationships for same nodes when loading from CSV

Hello guys,

I'm trying to load a data from a CSV file containing the following fields (header), as shown in the figure below:
2X_c_c98adad2e42d498f829e001003f38651e990c414.png

This CSV contains sales information of a specific store (CODIGOFILIAL). A person (CPF) can buy some products (CODIGOPRODUTO) that can be attached to the same basket (NUMEROUNICOCUPOM), which was bought in a specific date (DATAMOVIMENTO); as you can see on the highlighted text.

I'm trying to create the graph using the following cypher command:

LOAD CSV WITH HEADERS FROM 'file:///subset_vendas_cupom.csv' AS line
MERGE (n:Cliente {cpf:line.CPF})
MERGE (m:Cupom {codigoCupom:line.NUMEROUNICOCUPOM, dataMovimento:line.DATAMOVIMENTO})
MERGE (o:Produto {codigoProduto:line.CODIGOPRODUTO})
MERGE (p:Filial {filial:line.CODIGOFILIAL})
MERGE (n)-[:FEZ_PEDIDO]->(m)-[:CONTEM]->(o)-[:VENDIDO]->(p)

The problem is that it creates multiple relationships from a client to the same basket, because the basket contained several items which appear in different rows of my CSV file; as follows:

How can I make the highlighted relationships unique? Thanks in advance.

2 REPLIES 2

Solved this by separating the MERGE (n)-[:FEZ_PEDIDO]->(m)-[:CONTEM]->(o)-[:VENDIDO]->(p) into small pieces.

Great that you solved the issue.

The basic rule of thumb is that MERGE will create the entire pattern of the pattern doesn’t already exist in its entirety.