exposing ES index as a property
This commit is contained in:
parent
b658227f79
commit
ea13bdf23a
|
@ -0,0 +1,2 @@
|
|||
ES_INDEX = ip-90-147-167-25.ct1.garrservices.it
|
||||
# ES_INDEX = 192.168.100.26,192.168.100.21,192.168.100.29,192.168.100.25,192.168.100.70,192.168.100.71,192.168.100.72,192.168.100.73,192.168.100.44
|
|
@ -2,10 +2,17 @@ from elasticsearch import Elasticsearch
|
|||
from elasticsearch_dsl import *
|
||||
import logging
|
||||
|
||||
log = logging.getLogger("ES connector")
|
||||
log = logging.getLogger('ES connector')
|
||||
log.setLevel(logging.INFO)
|
||||
|
||||
ES_HOST = "ip-90-147-167-25.ct1.garrservices.it"
|
||||
def load_properties():
|
||||
with open('configuration.properties') as f:
|
||||
p = {}
|
||||
for line in f:
|
||||
if not line.startswith("#"):
|
||||
data = line.strip().split("=")
|
||||
p[data[0].strip()] = data[1].strip()
|
||||
return p
|
||||
|
||||
class ESObject(object):
|
||||
def __init__(self, id, pid, type, title, abstract, propagated_abstract):
|
||||
|
@ -25,7 +32,7 @@ class ESResponse(object):
|
|||
|
||||
class ESConnector(object):
|
||||
def __init__(self):
|
||||
self.index_host = ES_HOST
|
||||
self.index_host = [x.strip() for x in load_properties()['ES_INDEX'].split(',')]
|
||||
self.client = Elasticsearch(hosts=self.index_host, timeout=600000)
|
||||
|
||||
def query_after(self, query_string=None, start=0, i='propagation-after'):
|
||||
|
|
6
main.py
6
main.py
|
@ -6,10 +6,10 @@ from starlette.responses import FileResponse
|
|||
from fastapi import FastAPI, Form
|
||||
from es_connector import ESConnector
|
||||
|
||||
log = logging.getLogger("TPDL2020 webapp")
|
||||
log = logging.getLogger('TPDL2020 webapp')
|
||||
log.setLevel(logging.INFO)
|
||||
|
||||
log.info("TPDL2020 Webapp (re)started")
|
||||
log.info('TPDL2020 Webapp (re)started')
|
||||
|
||||
_CURDIR = os.path.dirname(os.path.abspath(__file__))
|
||||
|
||||
|
@ -32,7 +32,7 @@ def root():
|
|||
@app.get('/api/query/')
|
||||
def query_get(q='*', s:int=0, i=None):
|
||||
try:
|
||||
log.info("Executing query={q} start={s}".format(q=q, s=s))
|
||||
log.info('Executing query={q} start={s}'.format(q=q, s=s))
|
||||
result = es_connector.query_after(q, s, i)
|
||||
return result
|
||||
except Exception as e:
|
||||
|
|
Loading…
Reference in New Issue