Skip to content

Simple Python Flask application using Elasticsearch App Search

License

Notifications You must be signed in to change notification settings

radoondas/flask-app-search

Repository files navigation

Welcome

Welcome to simple demo Python Flask application using Elasticsearch App Search to showcase search implementation.

Documentation quick links:

Search app

How to

Quickstart

  1. Clone the repository
    • git clone https://github.com/radoondas/flask-app-search.git
    • navigate to the repository cd flask-app-search
  2. Setup your python Virtual environment (venv). Doc on venv howto. Or use any IDE of your choice to help you setup Virtual env (venv).
    • Activate venv source env/bin/activate or use IDE.
    • Install requirements pip install -r requirements.txt
  3. Start up Elastic app search cd docker; docker-compose start - first start of app search might take longer time
    • navigate to UI: http://localhost:3002
  4. In App Search UI Create 2 new data engines for app-search and blog-posts.
    • Engine 1: blog-posts
    • Engine 2: flask-app-search
  5. Import Movies dataset
    • cd ../data/movies
    • configure and run python index_movies.py
    • let import all documents (28,795 docs)
  6. Configure flask application
    • add your api key for APP_SEARCH_API_KEY in flask-app-search/.env
    • add your api key for APP_SEARCH_API_KEY_BLOG in flask-app-search/.env
  7. Run application either using yor IDE or from command line in your venv flask run
  8. Navigate to http://127.0.0.1:5000/ to check your application. Go to search page to start searching your movie dataset.

App Search installation

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

Dataset

The dataset is simple movie database from awesome-json-dataset.

Create engines

Follow the documentation to create 2 engines. blog-posts and flask-app-search using English language. More in the docu

List of engines

Data load

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
  • let the import finish

Check for errors and if you have 28,795 docs in your flask-app-search engine.

Flask app configuration

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.

Run demo

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.

Notes

  • I want to thank to this tutorial for inspiration and lots of great tips for skeleton of the Flask application.
  • Also, if you want to setup PyCharm IDE with running the Flask app, have a look on following blog post (setting-up-a-flask-application-in-pycharm) as well.

Search app with results

About

Simple Python Flask application using Elasticsearch App Search

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published