0
votes

I am new to neo4j and trying some stuff. I have two csv files: one with people, and one with friendship relationships.

I am trying to create a graph of friendship relationships between people, and I also want to do updates like: renaming people's names, changing the friendship relationships, and lastly I also want to run queries like "who are friends with Allen".

  • people.csv looks like this:

    id, name
    1, Allen
    2, John
    
  • friendship.csv looks like this:

    TO, FROM
    Allen, John
    

I have loaded these csv using code below:

LOAD CSV FROM 'file:///friendship.csv' AS line WITH line LIMIT 100 RETURN line

I have found different code for creating relationships, but I am confused about them.

Can anyone tell me how to create simple relationship of friendship mapping from the csv? and thereafter how to add more relationships using neo4j?

1

1 Answers

1
votes

Have you read the tutorial here: https://neo4j.com/developer/guide-importing-data-and-etl/ ?

A simple way to get started is, first create nodes from people.csv (assuming they're unique values, you can use a CREATE instead of a MERGE), for example

CREATE (:Person {id:line.id, name:line.name})

Set up indexes as required, in your case, on the persons name.

CREATE INDEX ON :Person(name);

Then create relationships by running a LOAD CSV on friendship.csv and MATCHing the nodes previously created

USING PERIODIC COMMIT
LOAD CSV FROM 'file:///friendship.csv' AS line WITH line
MATCH (to:Person {name: line.TO})
MATCH (from:Person {name: line.FROM})
MERGE (to)-[:FRIEND]->(from)