I have one relationship type (exported products from one country to another) named "EXPORTED_PRODUCT". On top of that i've created second relationship type based on the product code, as stated here:
MATCH (c1:Country)-[r:EXPORTED_PRODUCT]->(c2:Country) WHERE r.ProductHSCode="300220" MERGE (c1)-[:EXPORTED_PRODUCT_300220]->(c2)
Eveything looks fine, expect that any other link property, such as "ProductValue" and "ProductQuantity" don't copy at all.
Any ideas how can i duplicate these properties to the new relationship type?
MATCH (c1:Country)-[r1:EXPORTED_PRODUCT]->(c2:Country)
WHERE r.ProductHSCode="300220"
MERGE (c1)-[r2:EXPORTED_PRODUCT_300220]->(c2)
ON CREATE
SET r2 = r1
for some reason your query returns "(no changes, no records)", but this works:
MATCH (c1:Country)-[r:EXPORTED]->(c2:Country)
WHERE r.ProductHSCode="300220"
MERGE (c1)-[t:EXPORTED_PRODUCT_02]->(c2)
SET t.ProductHSCode=r.ProductHSCode,
t.ProductValue=r.ProductValue,
t.ProductQuantity=r.ProductQuantity,
t.Year=r.Year
It's simply because your relation already exist, that's why it's ON CREATE SET.
It will copy r1 in r2 only if the relation is created, if you want to do it systematically, your query is right. If you want to do it only when it matches an existing relationship you can use ON MATCH SET, so to recap you have :
SET
ON CREATE SET
ON MATCH SET
You also use both ON CREATE and ON MATCH when you need to define a different behaviour for each of them.
I would like to note that creating a new relationship type for each product is not a good practice. The property ProductHSCode on the relation EXPORTED_PRODUCT is quite sufficient to distinguish that. You just duplicate information with creating those new relations.
To clarify this exactly, we would need to know the full use case for these relationships and how they are queried later.