2
votes

I'm using Neo4j 2.2.0. I have two csv files. The first csv is a distinct list of all nodes, e.g. Friend nodes. The second csv is a list of the relationships between friends. I'm using the browser to load the data and create relationships. However when creating the relationships its creating new nodes for the Friends instead of using existing nodes.

Cypher for loading friends-

   USING PERIODIC COMMIT 10000
   LOAD CSV WITH HEADERS FROM "http://localhost/csv/Friends.csv" AS row
   CREATE (:Friends {Friend_Name: row.Friend_Name});

Cypher for loading relationships-

   USING PERIODIC COMMIT 10000
   LOAD CSV WITH HEADERS FROM "http://localhost/csv/Relationships.csv" AS row
   MATCH (Friend1:Friends {Friend_Name: row.Friend_Name})
   MATCH (Friend2:Relationships {Friend_Name: row.Friend_Name})
   CREATE (Friend1)-[:Friend_With]->(Friend2);

Please can someone point me in the right direction.

1

1 Answers

2
votes

It is normal, in your second LOAD CSV statement, you have this line :

MATCH (Friend2:Relationships {Friend_Name: row.Friend_Name})

You are using the Relationships label, which is wrong. You need to change to :

MATCH (Friend2:Friends {Friend_Name: row.Friend_Name})

Also, Friends look to me to a non appropriate label, a Person label would be more accurate as friendships are in fact what your relationships are telling you about the graph