My task is to import a number of friend or follow relationships into a simple neo4j graph db. My input data is a csv with the following structure:
owner,friend,type
Bob,Charlie,friend
Alice,Chris,follower
In the above example Charlie is a friend of Bob and Chris is a follower of Alice. I want to bulk import these into neo4j using LOAD CSV
but I'm having trouble creating the conditional relationships during import. The import code looks something like:
LOAD CSV WITH HEADERS FROM "file:./graph.csv" AS csvLine
WITH csvLine.owner AS owner,
csvLine.friend AS friend,
csvLine.type AS Type
MERGE (o:Person { name: owner })
MERGE (c:Person { name: friend })
MERGE (u)<-[:IS_FRIEND {type: Type}]-(c);
I'd rather have two types of relationships IS_FRIEND
and FOLLOWS
. But when I try conditional statements like:
CASE WHEN Type == "friend" THEN MERGE (u)<-[:IS_FRIEND]-(c) ELSE (u)<-[:FOLLOWS]-(c);
I receive syntax errors on the use of CASE
Is there a way to make conditional relationships during bulk import from csv like this?