☢️ Ask for help importing data to neo4j

Does anyone have a little time to help me in writing my import query!?
(I have a database of academic, writers and books I want to show relations between them) :disappointed_relieved:

how do you have the data stored currently? Do you have a schema in mind?

1 Like

Actually, I have them in SQL you can access them here

Come on community just a little help!

Hi there,

there are a few different ways to import from SQL to Neo4j, and some good articles on those options.

This article on importing data from relational db is probably the best place to start, with links to each of those approaches.

This article on Migrating from MySQL to Neo4j is also good, and further covers some of the concepts you'll need to learn with respect to data modeling for a graph db and how to translate some relational db concepts to graph accordingly.

This import data tutorial walks you through importing the Northwind db into Neo4j, and also covers differences between relational and graph data models.

Hope that helps!

Hi Andrew, Thanks but I didn't ask for documentation. actually I've seen them before.

I see.

I think if you want help with an import query, you'll need to provide something as a basis, such as what you've tried so far (and what is or isn't meeting your needs), your data model, your queries, and any other relevant info.

you right,
I think I have done that before here-1 and here-2, so I decided to ask it as a favor maybe this time someone wants to help :slight_smile: I tried my self-didn't succeeded so here I am.

Okay, so what about the examples isn't working for you?

The general idea is either that you use the CSV data to match on the nodes by ids (the id of one thing, and the foreign key of the other thing), then MERGE the relationship between them.

If you already imported all of the properties on the nodes, then that foreign key exists as a property on a node somewhere, and you can use that to look up the other node by id, then MERGE the relationship.

The last example on the here-2 thread shows a simplified version of this approach, but let's make some assumptions based upon the headers from your here-1 link.

From your Book.csv it looks like there's a property AuthorIds, which I'm assuming you imported as an integer list, and each id was a foreign key to a :Person with that integer Id property.

If so, then provided you have an index on :Person(Id) (for quick lookup of :Person nodes by id), you can use this query:

MATCH (b:Book)
MATCH (p:Person)
WHERE p.Id in b.AuthorIds 
MERGE (b)-[:WRITTEN_BY]->(p)

Let me know if any of those assumptions is off.

But in general, this is the approach you would use if you're working with an id list as opposed to just an id property (doing this by a single id property is easier of course, and an example was provided on the thread linked by here-2).

1 Like