├── Backend └── api.py ├── Frontend ├── app.py └── templates │ └── home.html └── README.md /Backend/api.py: -------------------------------------------------------------------------------- 1 | try: 2 | from flask import app,Flask 3 | from flask_restful import Resource, Api, reqparse 4 | import elasticsearch 5 | from elasticsearch import Elasticsearch 6 | import datetime 7 | import concurrent.futures 8 | import requests 9 | import json 10 | 11 | except Exception as e: 12 | print("Modules Missing {}".format(e)) 13 | 14 | 15 | app = Flask(__name__) 16 | api = Api(app) 17 | 18 | #------------------------------------------------------------------------------------------------------------ 19 | 20 | NODE_NAME = 'movies' 21 | es = Elasticsearch([{'host': 'localhost', 'port': 9200}]) 22 | 23 | #------------------------------------------------------------------------------------------------------------ 24 | 25 | 26 | class Movies(Resource): 27 | def __init__(self): 28 | self.rating = parser.parse_args().get("rating", None) 29 | self.baseQuery = { 30 | "size": 0, 31 | "aggs": { 32 | "rating": { 33 | "terms": { 34 | "field": "rating", 35 | "size": 10 36 | } 37 | } 38 | }, 39 | "query": { 40 | "bool": { 41 | "must": [], 42 | "filter": [], 43 | "should": [ 44 | { 45 | "wildcard": { 46 | "rating": { 47 | "value": None 48 | } 49 | } 50 | } 51 | ], 52 | "must_not": [] 53 | } 54 | } 55 | } 56 | 57 | def get(self): 58 | print("In") 59 | value = str(self.rating).upper() 60 | self.baseQuery["query"]["bool"]["should"][0]["wildcard"]["rating"]["value"] = "{}*".format(value) 61 | res = es.search(index=NODE_NAME, size=0, body=self.baseQuery) 62 | return res 63 | 64 | 65 | parser = reqparse.RequestParser() 66 | parser.add_argument("rating", type=str, required=True, help="title parameter is Required ") 67 | 68 | api.add_resource(Movies, '/rating') 69 | 70 | 71 | if __name__ == '__main__': 72 | app.run(debug=True) 73 | -------------------------------------------------------------------------------- /Frontend/app.py: -------------------------------------------------------------------------------- 1 | from flask import Flask 2 | from flask import request,redirect,render_template,session 3 | import requests 4 | import base64 5 | import requests 6 | 7 | app = Flask(__name__) 8 | 9 | 10 | @app.route('/', methods=["GET", "POST"]) 11 | def index(): 12 | return render_template("home.html") 13 | 14 | 15 | @app.route('/pipe', methods=["GET", "POST"]) 16 | def pipe(): 17 | 18 | data = request.form.get("data") 19 | 20 | payload = {} 21 | headers= {} 22 | 23 | url = "http://127.0.0.1:5000/rating?rating="+str(data) 24 | print(url) 25 | response = requests.request("GET", url, headers=headers, data = payload) 26 | 27 | return response.json() 28 | 29 | 30 | """ 31 |
32 | 33 |
34 | 35 | """ 36 | 37 | if __name__ == "__main__": 38 | app.run(debug=True, port=4000) -------------------------------------------------------------------------------- /Frontend/templates/home.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 |
24 | 25 |
s 26 | 27 | 28 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Auto Complete or Suggestion Sytem in Flask python using Elastic Search 2 | 3 | * learn how to make backend and frontend using python flask and elastic search 4 | 5 | ![Capture](https://user-images.githubusercontent.com/39345855/76691662-951fd000-6623-11ea-9d52-ec553dd60ddf.PNG) 6 | 7 | 8 | #### Video 9 | * links : https://www.youtube.com/watch?v=DNOdlbBaFBg 10 | 11 | 12 | --------------------------------------------------------------------------------