1
votes

i have a csv file containing activities (process graph) :

startActivityId,Name,endActivityId
 1,A,2
 2,B,3
 3,C,4
 4,D,5

so that it will look like this : A->B->C->D i imported the csv file successfully into neo4j server : using this Cypher query :

USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file:path/graph/activity.csv" AS row
CREATE (:Activity {startactivityId:row.startActivityId, Name: row.Name, endActivityId: row.endActivityId});

i then created an index on startactivityId :

CREATE INDEX ON :activity(startActivityId);

then i want to create the relationships between these nodes, so tried this cypher query :

USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file:path/graph/activity.csv" AS row
MATCH (startActivity:Activity {startActivityId: row.startActivityId})
MATCH (endActivity:Activity {startActivityId: row.endActivityId})
MERGE (startActivity)-[:LINKS_TO]->(endActivity);`

but no relationships created, nothing happens

i'm sure i missed something cause i'm new to cypher but i can't figure it out.

any ideas ?

1
You have mixed uppercase/lowercase in your csv and queries, for instance startActivityId in the csv but row.startactivityId in the query, and node property startactivityId in the create query but startActivityId in the match. Does it work if you fix that?jjaderberg
no i made the mistake here when i wrote this question, but in the cypher code it's correct,marcAntoine
is the structure of my query correct ?marcAntoine
Is that what your csv file actually looks like or did you align it just for posting here? Because if that's what your file looks like then your property values will have a bunch of blank spaces in them, and with the spaces there are no matching startActivityId and endActivityId. What does MATCH (n:Activity) RETURN n tell you?jjaderberg
no i just aligned to look more readable here, there is no blank spacesmarcAntoine

1 Answers

2
votes

I copied your updated csv (and removed the whitespace at the head of the first column) and ran your queries.

neo4j-sh (?)$ USING PERIODIC COMMIT LOAD CSV WITH HEADERS FROM "file:///Users/jonatan/src/doc/stackexchange/32225817.pdc" as row CREATE (:Activity {startActivityId:row.startActivityId, name:row.Name, endActivityId:row.endActivityId});                                            
+-------------------+
| No data returned. |
+-------------------+
Nodes created: 4
Properties set: 12
Labels added: 4
115 ms

neo4j-sh (?)$ USING PERIODIC COMMIT LOAD CSV WITH HEADERS FROM "file:///Users/jonatan/src/doc/stackexchange/32225817.pdc" as row MATCH (s:Activity {startActivityId:row.startActivityId}) MATCH (e:Activity {startActivityId:row.endActivityId}) MERGE (s)-[r:LINKS_TO]->(e) RETURN r;
+-------------------+
| r                 |
+-------------------+
| :LINKS_TO[2084]{} |
| :LINKS_TO[2085]{} |
| :LINKS_TO[2086]{} |
+-------------------+
3 rows
Relationships created: 3
178 ms

Three relationships created. To confirm that they are the right relationships I match and return the path (:Activity)-[:LINKS_TO]->().

neo4j-sh (?)$ MATCH p=(:Activity)-[:LINKS_TO]->() RETURN p;         
+-------------------------------------------------------------------------------------------------------------------------------------------+
| p                                                                                                                                         |
+-------------------------------------------------------------------------------------------------------------------------------------------+
| [Node[1415]{name:"A",startActivityId:"1",endActivityId:"2"},:LINKS_TO[2084]{},Node[1416]{name:"B",startActivityId:"2",endActivityId:"3"}] |
| [Node[1416]{name:"B",startActivityId:"2",endActivityId:"3"},:LINKS_TO[2085]{},Node[1417]{name:"C",startActivityId:"3",endActivityId:"4"}] |
| [Node[1417]{name:"C",startActivityId:"3",endActivityId:"4"},:LINKS_TO[2086]{},Node[1418]{name:"D",startActivityId:"4",endActivityId:"5"}] |
+-------------------------------------------------------------------------------------------------------------------------------------------+
3 rows
49 ms
neo4j-sh (?)$ 

It looks OK to me, not sure what's not working for you.

What does MATCH p=(:Activity)-[r]->() RETURN p; tell you?