Reputation: 117
I am trying to create a graph in neo4j using the following query:
LOAD CSV WITH HEADERS FROM 'file:///MyData.csv' AS row
MATCH (conta:Conta {nome: row.`Conta Origem`})
MATCH (contad:ContaD {nome: row.`Conta Destino`})
MERGE (conta)-[op:Movimentação]->(contad)
ON CREATE SET op.Valor = toFloat(row.Valor), op.`Tipo de Gasto` = row.`Tipo de Gasto`, op.`Tipo de movimentacao`=row.`Tipo de movimentacao`;
And the output is:
But this is not exactly what I want since the output is showing two graphs with the node 1
not connected; I mean, what I want is nodes 10
and 11
being connected to the red-centered node 1
.
The problem is that they are representing transactions through bank accounts, and accounts 11 and 10 are origin accounts to account 1 which, in its turn, is an origin account for all the others.
How can I proceed and change the query so I can get it right? I am new to cypher, so I am sorry if it is obvious.
Edit: a sample of the data is shown below:
Upvotes: 1
Views: 60
Reputation: 12684
In the sample csv file that you showed, the row on 2016-01-15 06:00:00 that has node 11 as origem and node 1 as destino was NOT connected because the match on :ContaD did not find node 1;
Let say;
line1: MATCH (conta:Conta {nome: row.`Conta Origem`})
line2: MATCH (contad:ContaD {nome: row.`Conta Destino`})
line3: MERGE (conta)-[op:Movimentação]->(contad)
ON CREATE SET op.Valor = toFloat(row.Valor), op.`Tipo de Gasto` = row.`Tipo de Gasto`, op.`Tipo de movimentacao`=row.`Tipo de movimentacao`;
In line1; Conta is node11 which is okey and found
In line2; ContaD has no node1 so no rows returned
In line3; Skip this line since line2 is empty row and go to next row in excel
Thus node11 (a node Conta) will NOT be connected to node1 as a node ContaD.
Suggestion: Why you need a label ContaD separated with Conta? You can create another label ContaD which contains the same nodes with Conta. The syntax to add another label to an existing node.
match (n:Conta) set n :ContaD
You might get an error now because ContaD is already created. Go back to your script when you created the nodes and edges and create the label ContaD together with Conta
Upvotes: 1