diff --git a/haystack/api/controller/feedback.py b/haystack/api/controller/feedback.py index c8d9a123d1..736d91ce79 100644 --- a/haystack/api/controller/feedback.py +++ b/haystack/api/controller/feedback.py @@ -5,7 +5,6 @@ from fastapi.responses import JSONResponse from pydantic import BaseModel -from haystack.api import application from haystack.api.config import ( DB_HOST, DB_USER, @@ -19,6 +18,7 @@ EXCLUDE_META_DATA_FIELDS, ) from haystack.api.config import DB_INDEX_FEEDBACK +from haystack.api.elasticsearch_client import elasticsearch_client from haystack.database.elasticsearch import ElasticsearchDocumentStore from elasticsearch.helpers import scan @@ -57,7 +57,7 @@ def feedback(model_id: int, request: Feedback): content="Invalid 'feedback'. It must be one of relevant, fake, outdated or irrelevant", ) feedback_payload["model_id"] = model_id - application.elasticsearch_client.index(index=DB_INDEX_FEEDBACK, body=feedback_payload) + elasticsearch_client.index(index=DB_INDEX_FEEDBACK, body=feedback_payload) @router.get("/models/{model_id}/export-faq-feedback") @@ -68,7 +68,7 @@ def export_faq_feedback(model_id: int): relevant_feedback_query = { "query": {"bool": {"must": [{"term": {"feedback": "relevant"}}, {"term": {"model_id": model_id}}]}} } - result = scan(application.elasticsearch_client, index=DB_INDEX_FEEDBACK, query=relevant_feedback_query) + result = scan(elasticsearch_client, index=DB_INDEX_FEEDBACK, query=relevant_feedback_query) per_document_feedback = defaultdict(list) for feedback in result: diff --git a/haystack/api/elasticsearch_client.py b/haystack/api/elasticsearch_client.py new file mode 100644 index 0000000000..f56aaa38bb --- /dev/null +++ b/haystack/api/elasticsearch_client.py @@ -0,0 +1,7 @@ +from elasticsearch import Elasticsearch + +from haystack.api.config import DB_HOST, DB_USER, DB_PW + +elasticsearch_client = Elasticsearch( + hosts=[{"host": DB_HOST}], http_auth=(DB_USER, DB_PW), scheme="http", ca_certs=False, verify_certs=False +)