Skip to content
Snippets Groups Projects
Commit 11df7450 authored by felixwelter's avatar felixwelter
Browse files

Add basic interface to elastic search

parents
No related branches found
No related tags found
Loading
.idea
FROM python:3.8
RUN pip install elasticsearch-dsl==6.4.0 Flask==1.1.2
RUN mkdir app
COPY . app
WORKDIR app
#RUN pip install -r requirements.txt
EXPOSE 5000
ENV FLASK_APP=app.py
ENV SERVER_NAME=0.0.0.0
ENTRYPOINT flask run -h 0.0.0.0
\ No newline at end of file
app.py 0 → 100644
from flask import Flask, render_template, request, redirect, send_file
from elasticsearch_dsl import connections, Search
app = Flask(__name__)
connections.create_connection(hosts=['34.121.207.248:9200'], timeout=20)
@app.route('/search')
def index():
term = request.args.get('term')
s = Search(index="en_wiki") \
.query("match", title=term) \
.exclude("match", description="beta")
response = s.execute()
if len(response) > 0:
return response[0].text
s = Search(index="en_wiki") \
.query("match_phrase", title=term) \
.exclude("match", description="beta")
response = s.execute()
if len(response) > 0:
return response[0].text
s = Search(index="en_wiki") \
.query("match", text=term) \
.exclude("match", description="beta")
response = s.execute()
if len(response) > 0:
return response[0].text
s = Search(index="en_wiki") \
.query("match_phrase", text=term) \
.exclude("match", description="beta")
response = s.execute()
if len(response) > 0:
return response[0].text
return "No hits"
if __name__ == '__main__':
app.debug = True
app.run(host="0.0.0.0")
elasticsearch-dsl>=6.0.0,<7.0.0
Flask
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment