Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cyclic import of Elasticsearch client #59

Merged
merged 1 commit into from
Apr 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions haystack/api/controller/feedback.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

Expand Down Expand Up @@ -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")
Expand All @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions haystack/api/elasticsearch_client.py
Original file line number Diff line number Diff line change
@@ -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
)