Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
09-01-2018 04:08 PM
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?
09-01-2018 05:20 PM
Can you share more detail? Like the structure of your files and the command you are using to load them?
09-02-2018 07:05 PM
thanks @michael.hunger for your replay, this is the diagram in the end i will add more images about structures.
// 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
09-03-2018 08:47 PM
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.
09-03-2018 08:53 PM
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!?
09-03-2018 08:59 PM
MATCH (b:Book)
OPTIONAL MATCH (p:Person { personID: b.authorID})
MERGE (b)-[:WRITTEN_BY]->(p)
Typed, not tested.
All the sessions of the conference are now available online