Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
03-25-2022 08:55 AM
I have a long list of uuids for nodes I know to be the same stored in a csv (uuid1 and uuid2). When I use the following simple query, it only yields the result for the first row and does not continue on with the rest of the sheet. Any ideas?
LOAD CSV WITH HEADERS FROM 'file:///XXX.csv' AS row
MATCH (a1:Person), (a2:Person)
WHERE a1.uuid = row.uuid1 AND a2.uuid = row.uuid2
WITH head(collect([a1,a2])) as nodes
CALL apoc.refactor.mergeNodes(nodes,{
properties: "discard",
mergeRels:true
})
YIELD node
RETURN node
03-26-2022 03:24 AM
Hello @mkretsch
Can you share the CSV file here please? (you must replace the .csv
extension by .txt
).
Regards,
Cobra
04-08-2022 06:47 AM
It should depend on the csv, but if you want to merge (a1:Person)
and (a2:Person)
,
I think you have to remove head
and collect
functions.
With your query, you group every result into the collect
and with head
you pick only the 1st result.
Instead, this query should work:
LOAD CSV WITH HEADERS FROM 'file:///XXX.csv' AS row
MATCH (a1:Person), (a2:Person)
WHERE a1.uuid = row.uuid1 AND a2.uuid = row.uuid2
WITH [a1,a2] as nodes
// apoc.refactor.mergeNodes part
or even better, to avoid "cartesian product" issues (due to MATCH (a1:Person), (a2:Person)
, in fact, in neo4j browser you can see the query underlined in yellow, because is a warning
),
you could execute:
LOAD CSV WITH HEADERS FROM 'file:///XXX.csv' AS row
MATCH (a1:Person)
WHERE a1.uuid = row.uuid1
WITH a1
MATCH (a2:Person)
WHERE a2.uuid = row.uuid2
// apoc.refactor.mergeNodes part
All the sessions of the conference are now available online