I will be pasting the file.
from flask import *
from flask_restful import Api
from elasticsearch import Elasticsearch
es = Elasticsearch("http://localhost:9200")
from matches import search
import pandas
import spacy
from spacy.lang.en.stop_words import STOP_WORDS as stopwords
import json
import numpy as np
from add import add
from full_text import full_text
from multimatch import multi_match
from matchalles import search_all
app = Flask(name)
app.secret_key = 'kingom'
api = Api(app)
@app.route('/')
def home():
return render_template('home.html')
@app.route('/total' , methods =["GET", "POST"])
def get_all():
search_all()
return render_template('list.html')
@app.route('/all' , methods =["GET", "POST"])
def getall():
return search_all()
@app.route('/search' , methods =["GET", "POST"])
def search_speci():
global useranswer
global elastic_df
global search_inpt
# It Posts Request
if request.method=="POST":
# The search input check
search_inpt = request.form.get("seab")
# This is for checking elasticsearch for the search
response = es.search(index="location" , query={"match":{useranswer:search_inpt}})
# Starts for the returning
elastic_docs = response["hits"]["hits"]
# Printing the documents number which are found
print ("documents returned:", len(response["hits"]["hits"]))
# Changeing the output to Table then to normal json
fields = response
elastic_df = pandas.DataFrame(fields)
json_data = elastic_df.to_json()
# returning the json_data
return json_data
return render_template("searchab.html" )
@app.route('/add', methods =["GET", "POST"])
def add_docs():
global about_add
# Getting the values of user
if request.method == "POST":
about_add = request.form.get("about")
where_add = request.form.get("where")
# doc for adding
doc1 = {
"about": about_add,
"where": where_add
}
# code for adding docs
response = es.index(
index="location",
document=doc1,
id = number
)
return about_add , where_add
return render_template("add.html")
@app.route('/multi' , methods =["GET", "POST"])
def multi():
multi_match()
return render_template("multisearch.html")
@app.route('/fulltext' , methods =["GET", "POST"])
def fulltext():
# creating stages and appling filters to it
if request.method=="POST":
# data = es.search(index="location" , query={"match_all":{}})
data = search_inpt = request.form.get("speci")
# Defining the dataframe and using it
df = pandas.DataFrame(data=data)
stage2 = df.apply(lambda x: len(str(x).split()))
stage3 = stage2.apply(lambda x: cont_to_exp(x))
stage4 = stage3.apply(lambda x: re.sub(r'[^\w ]+', "", x))
stage5 = stage4.apply(lambda x: ' '.join(x.split()))
response = es.search(index="location" , query={"match":{"where": stage5}})
# Changeing the output to Table then to normal json
fields = response
elastic_df = pandas.DataFrame(fields)
json_data = elastic_df.to_json()
# returning the json_data
return json_data
return render_template("searchwh.html")
@app.route('/update' , methods =["GET", "POST"])
def update():
global about_update
# Getting the values of user
if request.method == "POST":
about_update = request.form.get("about")
where_update = request.form.get("where")
user_id = request.form.get("user_id")
# doc for adding
doc1 = {
"about": about_update,
"where": where_update
}
# code for adding docs
response = es.index(
index="location",
document=doc1,
id = user_id
)
return "About and Where Updated", doc1
return render_template('update.html')
@app.route('/delete' , methods =["GET", "POST"])
def delete():
if request.method=="POST":
search_inpt = request.form.get("dele")
dele = es.delete(index = "location",id = search_inpt)
search()
return "The Doc Has Been Successfully Deleted"
return render_template('delete.html')
if name == 'main':
app.run(port=5000, debug=True)
{"took":{"total":4,"successful":4,"skipped":4,"failed":4,"max_score":4,"hits":4},"timed_out":{"total":false,"successful":false,"skipped":false,"failed":false,"max_score":false,"hits":false},"_shards":{"total":1.0,"successful":1.0,"skipped":0.0,"failed":0.0,"max_score":null,"hits":null},"hits":{"total":{"value":1,"relation":"eq"},"successful":null,"skipped":null,"failed":null,"max_score":1.0,"hits":[{"_index":"location","_id":"1","_score":1.0,"_source":{"about":"Om","where":"Bombay"}}]}}
I only want this :[{"_index":"location","_id":"1","_score":1.0,"_source":{"about":"Om","where":"Bombay"}}]}}