Create nodes and relations conditionally when load

2019-05-18 03:33发布

I have a data set in csv format. One of the fields is a type, like an enumeration. Based on this type I need to create different types nodes and relations when loading the data using csv load. You could call a row in the csv for a super type having an attribute defining its subtype.

I'm not really able to figure out how this can be done in cypher. Is my only option to split the one csv file into a csv file per type and run different cyphers ?

标签: csv neo4j cypher
1条回答
劫难
2楼-- · 2019-05-18 04:15

This document on conditional statements helps.

Here is a simple example for loading based on a column value:

Data: a,b Ford,car Chevy,truck Mazda,car GMC,truck F150,truck

Cypher code:

load csv with headers from "file:/testfile.csv" as row
FOREACH(ignoreMe IN CASE WHEN trim(row.b) = "truck" THEN [1] ELSE [] END | MERGE (p:Truck {vehicleType: row.a}))
FOREACH(ignoreMe IN CASE WHEN trim(row.b) = "car" THEN [1] ELSE [] END | MERGE (p:Car {vehicleType: row.a}))

When you are done, you will have nodes created of different types.

查看更多
登录 后发表回答