Skip to content

Instantly share code, notes, and snippets.

@fferegrino
Last active June 18, 2018 19:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fferegrino/91ed8a64fd8b1657047caed10d9d8e98 to your computer and use it in GitHub Desktop.
Save fferegrino/91ed8a64fd8b1657047caed10d9d8e98 to your computer and use it in GitHub Desktop.
MovieLens database insert
LOAD CSV WITH HEADERS FROM 'file:///movies.clean.csv' as l
CREATE (m:Movie{movieId:toInteger(l.movieId), tmdbId:l.tmdbId, imdbId:l.imdbId, title:l.title, year:date(l.year)})
CREATE INDEX ON :Movie(movieId)
LOAD CSV WITH HEADERS FROM 'file:///users.csv' as l
CREATE (u:User{userId:toInteger(l.userId)})
CREATE INDEX ON :User(userId)
LOAD CSV WITH HEADERS FROM 'file:///genres.csv' as l
MERGE (g:Genre{name:l.genre})
WITH g,l.movieId as movieId
MATCH (m:Movie{movieId:toInteger(movieId)})
MERGE (m)-[:IsGenre]->(g)
LOAD CSV WITH HEADERS FROM 'file:///ratings.csv' as l
MATCH (m:Movie{movieId:toInteger(l.movieId)})
MATCH (u:User{userId:toInteger(l.userId)})
CREATE (u)-[:Rates{rating:toFloat(l.rating), time:datetime(l.time)}]->(m)
LOAD CSV WITH HEADERS FROM 'file:///tags.csv' as l
MATCH (m:Movie{movieId:toInteger(l.movieId)})
MATCH (u:User{userId:toInteger(l.userId)})
CREATE (u)-[:Tags{tag:l.tag, time:datetime(l.time)}]->(m)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment