-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
29 lines (25 loc) · 965 Bytes
/
Copy pathapp.py
File metadata and controls
29 lines (25 loc) · 965 Bytes
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
26
27
28
29
from flask import Flask, render_template, request
from elasticsearch import Elasticsearch, exceptions
app = Flask(__name__)
es = Elasticsearch()
keywords = ['movies','sports','music','finance','technology','fashion','science','travel','health','cricket','india']
@app.route('/')
def index():
query = request.args.get('q', '')
res = es.search(
index="faaltu",
body={
"query": {"match": {"text": query}},
"size": 750 # max document size
})
coords, results = [], []
if res["hits"]["hits"]:
coords = [r["_source"]["coordinates"] for r in res["hits"]["hits"]]
results = [r["_source"]["text"] for r in res["hits"]["hits"]]
return render_template("index.html",
coords=coords,
keywords=keywords,
query=query,
results=results)
if __name__ == "__main__":
app.run(debug=True)