cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How Connect columns in CSV files

Hi, lately I have a issue which I couldn't connect a column from my first CSV import file through a second one to the a column in the 3th CSV file,

What I mean is I have 3 CSV files, in first one a list of books and information about them in second one a list of books ID's and also writter ID's in third one we have writters information, what I want to do is create graph between book and writter also show the information about them.
Any idea?

5 REPLIES 5

Can you share more detail? Like the structure of your files and the command you are using to load them?

thanks @michael.hunger for your replay, this is the diagram in the end i will add more images about structures.


i have use this lines to import my csv files:

// Create academy
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file:///academy.csv" AS row
CREATE (:Academy {academyID: TOINT(row.id), academyName: row.Name, cityName: row.CityItalianName});

  // Create Person
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file:///person.csv" AS row
CREATE (:Person {personID: TOINT(row.Id), personName: row.Surname, personFamily: row.Forename, personBirth: TOINT(row.BirthDate), personDeath: TOINT(row.DeathDate), personNation: row.Nationality});

  // Create Book
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "file:///book.csv" AS row
CREATE (:Book {bookID: TOINT(row.Id), academyID: TOINT(row.AcademyIds), authorID: TOINT(row.AuthorIds), bookSubject: row.Subjects});

  // Create Indexs
CREATE INDEX ON :Academy(academyID);
CREATE INDEX ON :Academy(academyName);
CREATE INDEX ON :Academy(cityID);
CREATE INDEX ON :Academy(cityName);
CREATE INDEX ON :Person(personID);
CREATE INDEX ON :Person(personName);
CREATE INDEX ON :Person(personFamily);
CREATE INDEX ON :Person(personBirth);
CREATE INDEX ON :Person(personDeath);
CREATE INDEX ON :Person(personNation);
CREATE INDEX ON :Book(bookID);
CREATE INDEX ON :Book(academyID);
CREATE INDEX ON :Book(authorID);
CREATE INDEX ON :Book(bookSubject);

  // Create Relations books - persons
MATCH(b:Book)
MERGE(b.bookSubject)-[r:WRITE_BY]->(b.authorID)
return r ;

MATCH (p:Person),(b:Book)
MERGE (b)-[r:WRITE_BY]->(p)
RETURN r;

MATCH (p:Person),(a:Academy)
MERGE (p)-[r:RELATED_TO]->(a)
RETURN r;

MATCH (b:Book),(a:Academy)
MERGE (b)-[r:CONNECTED]->(a)
RETURN r;

these are structures
1X_cf6f5dfc0f6b584adb7a5fe054e5687f3b4858b3.png 1X_a9f0d120963737e67650dd24de6cbe0c8378bc87.png

Hi Moji,

You have many issues in your import, even before you worry about establishing relationships. For one thing, it looks like you are trying to convert an array of academy and author ID's to an int. Let's say those were not arrays. Even so, you cannot create relationships between properties on a node. Only between nodes. MERGE(b.bookSubject)-[r:WRITE_BY]->(b.authorID) makes no sense. `MERGE (b)-[:WRITE_BY]->(a:Author { personId: b.authorID}) might go in a better direction, but I'm still talking nonsense, because you'll need more graph design first.

You may have general gaps in your understanding, and should read the docs further.

Thanks but for now could you suggest me a little shortcut to connect books to Persons in simple way?
Should I import each column separately!?

MATCH (b:Book)
OPTIONAL MATCH (p:Person { personID: b.authorID})
MERGE (b)-[:WRITTEN_BY]->(p)

Typed, not tested.