Simple Python Flask application using Elasticsearch App Search
APACHE-2.0 License
Welcome to simple demo Python Flask application using Elasticsearch App Search to showcase search implementation.
Documentation quick links:
git clone https://github.com/radoondas/flask-app-search.git
cd flask-app-search
source env/bin/activate
or use IDE.pip install -r requirements.txt
cd docker; docker-compose start
- first start of app search might take longer time
http://localhost:3002
blog-posts
flask-app-search
cd ../data/movies
python index_movies.py
APP_SEARCH_API_KEY
in flask-app-search/.env
APP_SEARCH_API_KEY_BLOG
in flask-app-search/.env
flask run
http://127.0.0.1:5000/
to check your application. Go to search page to start searching your movie dataset.To install App Search, you can either follow the documentation or simply try to run docker-compose provided in the repository.
Navigate to docker
folder and execute docker-compose start
The dataset is simple movie database from awesome-json-dataset.
Follow the documentation to create 2 engines. blog-posts
and flask-app-search
using English language.
More in the docu
In order to index this dataset in to App search engine, we have to split the big file in to small chunks of size 100 due to restrictions on app search side.
We will use script prepared for the task index_movies.py
which will do the job for us. Just configure 2 variables and you are ready to go.
host_identifier = 'localhost:3002/api/as/v1'
api_key = 'private-yourkey'
cd data/movies
python index_movies.py
Check for errors and if you have 28,795 docs in your flask-app-search
engine.
In order to configure properly the demo app, configure your engines api key. Navigate to .env
file and change
following lines with your api keys. You can choose different levels of access and by default, you will be fine with just
one key which covers both engines. For the sake of demo, I created additional access api key for blog posts.
APP_SEARCH_API_KEY='search-sm77kdfd3mvtdykg4pfvusiq'
APP_SEARCH_API_KEY_BLOG='private-7369ct1thtwppsq73s122zip'
Note, that if you are using HTTPS endpoint of Elastic SaaS or your own TLS endpoint for App Search, do not use protocol part (https://
)
in configuration APP_SEARCH_BASE_ENDPOINT='localhost:3002/api/as/v1'
.
Configuration value of APP_SEARCH_USE_HTTPS=True/False
will pick correct protocol.
To tun the application, you simply execute flask run
command in your venv or use IDE of your choice to execute.
Then, navigate your browser to http://127.0.0.1:5000/
and enjoy your app.