Create nodes and relations conditionally when loading nodes from csv in Neo4j

大城市里の小女人 提交于 2020-01-13 03:38:27

问题


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 ?


回答1:


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.



来源:https://stackoverflow.com/questions/25557457/create-nodes-and-relations-conditionally-when-loading-nodes-from-csv-in-neo4j

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!