Building recommenders with Elastic Graph!
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.

Elastic Graph Recommender

Blog Post | Demo

Building recommenders with Elastic Graph! This app makes movie recommendations using Elastic graph based on the Movielens data set. Movielens is a well known open data set with user movie ratings.

We use this data alongside The Movie Database(TMDB). TMDB has all the movie details such as title, image URL, etc.

ETL and data prep

In the etl/ folder there are several Python scripts for importing movielens & TMDB data into Elasticsearch into two collections.

  • One index, movielens stores user view data. Each record is a user and the movielens identifiers of movies they liked. The primary key is a movielens user id. These documents hold a single field liked_movies -- the movielens ids of the movies this user liked.
  • Another index ml_tmdb uses the mapping from movielens ids -> tmdb ids to store details about each movies (title, poster image URL, etc). The primary key is the movielens movie id.

Import Movielens ratings

  • is a shell script for downloading the latest movielens data (ml-20m) and unpacking it to the ml-20m folder.
  • is a Python 2.7 script for importing movielens data into Elasticsearch

Import TMDB movie details

It's recommended you get the prepared source data file ml_tmdb.json from someone. But you can recreate it with the scripts below

  • crawls the movielens TMDB movies into tmdb.json
  • creates ml_tmdb.json, which is tmdb.json with the movielens as the primary identifier
  • indexes ml_tmdb.json into Elasticsearch

Angular App

The app/ folder holds an angular app for querying Elasticsearch via the graph API for recommendations.

Bootstrap app

See the app/ shell script for bootstrapping bower and npm dependencies

Run the app

Start a dumb web server in the app/ dir,

cd app/


Tests are run via Karma, you can run app/ to run tests. When debugging, I use the following command:

node_modules/karma/bin/karma start --no-single-run --log-level debug --auto-watch --browsers Chrome

which runs Karma in Chrome, autowatching the source files.


By rubbing two sticks together to start a fire

  • However you like to deploy stuff, there's a script that lists the steps taken to provision an Ubuntu box with Elastic Graph. NOTE this script is meant for development purposes, it does several non-secure things like opens up Elasticsearch to the world and has very liberal CORS permissions.

By using Docker

Start the docker images via:

docker login   # ask Eric for credentials

docker run -d -p 9200:9200 -p 9300:9300 --name elasticsearch
docker run -d -p 8000:8000 --name app -e ELASTICSEARCH_URL=http://localhost:9200

If you are deploying in the cloud, remember that the ELASTICSEARCH_URL is pointing to the public URL for the Elasticsearch node, so update accordingly!

Load the demo data via:

docker exec -it elasticsearch python /etl/
docker exec -it elasticsearch python /etl/ http://localhost:9200 /etl/ml_tmdb.json
docker exec -it elasticsearch python /etl/ http://localhost:9200 /etl/ml_tmdb.json /etl/ml-20m/ratings.csv

By using a blow torch

docker login   # ask Eric for credentials
docker-compose up

Browse to http://localhost:8000 to try it out!

Building Docker images

Build the docker images from scratch via:

docker build -t elastic-graph-recommender/elasticsearch -f deploy/elasticsearch/Dockerfile .
docker build -t elastic-graph-recommender/app -f deploy/app/Dockerfile .
docker build -t elastic-graph-recommender/init -f deploy/init/Dockerfile .

Deploy to our private Docker registry

docker login

docker tag elastic-graph-recommender/elasticsearch
docker tag elastic-graph-recommender/app
docker tag elastic-graph-recommender/init

docker push
docker push
docker push