Demo code for the following talk: "Shaping Elasticsearch for Recommendation System"
In order to create a working environment, the docker is used. To start it, please, follow the next steps.
- Launch the docker daemon.
- Get to the repository root folder:
cd ~/projects/talk-es-for-reco/
- Run the docker containers:
docker compose up
- In another terminal instance, run
docker ps
, and check that both containers are running:container-python
container-elasticsearch
- In another terminal instance, get into the container with python environment:
docker exec -it container-python /bin/bash
- Inside the container, run python scripts like this:
python <path/to/script.py>
In order to set up Elasticsearch indices and upload data into the corresponding indices,
run the following command in the container with python environment:
python /usr/src/app/scripts/setup.py
In the repository, two features are introduced: search and recommendation.
The search.py
script utilizes the Elasticsearch library to search
the 'users' index based on the provided search input.
Usage:
- Modify the
SEARCH_INPUT
variable to specify the search term. - Run the script:
python /usr/src/app/scripts/search.py
The search results will be printed to the console.
The recommendation.py
script utilizes the Elasticsearch
to recommend posts to a user based on various factors. It applies a scoring mechanism to rank posts
and provide personalized recommendations to the user.
Usage:
- Modify the
USER_ID
variable to specify the user for whom posts should be recommended. - Run the script:
python /usr/src/app/scripts/recommendation.py
The recommended posts will be printed to the console, sorted from the most relevant to the least relevant one.