Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
E
Elastic Search Middleware
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Welter, Felix
Elastic Search Middleware
Commits
5b4a2a55
Commit
5b4a2a55
authored
Aug 31, 2020
by
felixwelter
Browse files
Options
Downloads
Patches
Plain Diff
Switch to new request format
parent
20a6127d
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
app.py
+25
-9
25 additions, 9 deletions
app.py
templates/index.html
+15
-0
15 additions, 0 deletions
templates/index.html
with
40 additions
and
9 deletions
app.py
+
25
−
9
View file @
5b4a2a55
from
flask
import
Flask
,
render_template
,
request
,
redirect
,
send_file
from
flask
import
Flask
,
render_template
,
request
,
redirect
,
send_file
,
jsonify
from
elasticsearch_dsl
import
connections
,
Search
from
elasticsearch_dsl
import
connections
,
Search
import
os
import
os
...
@@ -7,39 +7,55 @@ app = Flask(__name__)
...
@@ -7,39 +7,55 @@ app = Flask(__name__)
connections
.
create_connection
(
hosts
=
[
os
.
getenv
(
'
ES_HOST
'
,
'
localhost
'
)],
timeout
=
20
)
connections
.
create_connection
(
hosts
=
[
os
.
getenv
(
'
ES_HOST
'
,
'
localhost
'
)],
timeout
=
20
)
@app.route
(
'
/search
'
)
@app.route
(
'
/test
'
)
def
test_page
():
return
render_template
(
'
index.html
'
)
def
make_text_response
(
text
):
print
(
text
[:
100
])
return
jsonify
({
"
type
"
:
"
text
"
,
"
text
"
:
text
})
@app.route
(
'
/search
'
,
methods
=
[
'
POST
'
])
def
index
():
def
index
():
term
=
request
.
args
.
get
(
'
term
'
)
term
=
request
.
form
.
get
(
'
term
'
)
print
(
term
)
s
=
Search
(
index
=
"
en_wiki
"
)
\
s
=
Search
(
index
=
"
en_wiki
"
)
\
.
query
(
"
match
"
,
title
=
term
)
\
.
query
(
"
match
"
,
title
=
term
)
\
.
exclude
(
"
match
"
,
description
=
"
beta
"
)
.
exclude
(
"
match
"
,
description
=
"
beta
"
)
response
=
s
.
execute
()
response
=
s
.
execute
()
if
len
(
response
)
>
0
:
if
len
(
response
)
>
0
:
return
response
[
0
].
text
return
make_text_response
(
response
[
0
].
text
)
s
=
Search
(
index
=
"
en_wiki
"
)
\
s
=
Search
(
index
=
"
en_wiki
"
)
\
.
query
(
"
match_phrase
"
,
title
=
term
)
\
.
query
(
"
match_phrase
"
,
title
=
term
)
\
.
exclude
(
"
match
"
,
description
=
"
beta
"
)
.
exclude
(
"
match
"
,
description
=
"
beta
"
)
response
=
s
.
execute
()
response
=
s
.
execute
()
if
len
(
response
)
>
0
:
if
len
(
response
)
>
0
:
return
response
[
0
].
text
return
make_text_response
(
response
[
0
].
text
)
s
=
Search
(
index
=
"
en_wiki
"
)
\
s
=
Search
(
index
=
"
en_wiki
"
)
\
.
query
(
"
match
"
,
text
=
term
)
\
.
query
(
"
match
"
,
text
=
term
)
\
.
exclude
(
"
match
"
,
description
=
"
beta
"
)
.
exclude
(
"
match
"
,
description
=
"
beta
"
)
response
=
s
.
execute
()
response
=
s
.
execute
()
if
len
(
response
)
>
0
:
if
len
(
response
)
>
0
:
return
response
[
0
].
text
return
make_text_response
(
response
[
0
].
text
)
s
=
Search
(
index
=
"
en_wiki
"
)
\
s
=
Search
(
index
=
"
en_wiki
"
)
\
.
query
(
"
match_phrase
"
,
text
=
term
)
\
.
query
(
"
match_phrase
"
,
text
=
term
)
\
.
exclude
(
"
match
"
,
description
=
"
beta
"
)
.
exclude
(
"
match
"
,
description
=
"
beta
"
)
response
=
s
.
execute
()
response
=
s
.
execute
()
if
len
(
response
)
>
0
:
if
len
(
response
)
>
0
:
return
response
[
0
].
text
return
make_text_response
(
response
[
0
].
text
)
return
"
No hits
"
return
jsonify
({
"
type
"
:
"
miss
"
})
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
...
...
This diff is collapsed.
Click to expand it.
templates/index.html
0 → 100644
+
15
−
0
View file @
5b4a2a55
<!DOCTYPE HTML>
<html>
<head>
<title>
Slide index
</title></head>
<body>
<h1>
Query
</h1>
<form
action=
"search"
method=
"post"
>
<input
name=
"term"
placeholder=
"term"
><br>
<input
name=
"context"
placeholder=
"context"
><br>
<input
type=
"submit"
value=
"Query"
>
</form>
</body>
</html>
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment