Is it possible in cypher to create different relationship between nodes based on the value of csv using the import functionality .
Eg : For a given csv data
product_id user_id action
1 1 VIEW
1 2 PURCHASE
I need to create product node(product_id) , user node(user_id) and either VIEW or PURCHASE relationship between 'user' and product node based on the value of 'action' field in csv .
Below are the approaches I tried . I know the syntax is incorrect but just to give an idea what I am trying to do .
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file://pathto/product-event.csv" AS csvLine
FIELDTERMINATOR ','
MERGE ( prod:Product{pid: toInt(csvLine.product_id)} )
MERGE ( usr:User { cid: toInt(csvLine.userid) })
WITH prod,usr , CASE
WHEN csvLine.action ='VIEW' THEN 'VIEW'
WHEN csvLine.action ='PURCHASE' THEN 'PURCHASE'
ELSE 'VIEW' END AS action
MERGE (usr)-[:action]->(prod)
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file:///pathto/product-event.csv" AS csvLine
FIELDTERMINATOR ','
MERGE ( prod:Product {pid: toInt(csvLine.productid) } )
MERGE ( usr:User { cid: toInt(csvLine.userid) }
)
ON CREATE SET
prod.created=timestamp()
WHERE csvLine.action = 'VIEW'
MERGE (cust)-[:VIEW]->(prod)
WHERE csvLine.action = 'PURCHASE'
MERGE (usr)-[:PURCHASE]->(prod)
There may be simple way to do it . but I am not getting any reference online. Thanks.