Repository: deepset-ai/haystack

Issue:
Custom "question" field for FAQ matching in Finder
![fac-qa](https://user-images.githubusercontent.com/8537280/78766371-c3db5d00-79bb-11ea-893f-2b340bfbe1ad.PNG)
Now, we have solved this problem, thanks.
But the new problem is when we use faq-qa, it would show 500 Internal server error, but it's ok with doc-qa, do you have any idea?

_Originally posted by @laifuchicago in https://github.com/deepset-ai/haystack/issues/57#issuecomment-610843642_


Discussion:
Hi @laifuchicago, the `Finder` currently expects the documents in Elasticsearch to have a `question` field when doing `faq-qa`. Can you check if your documents have it?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed in 14 days if no further activity occurs.


Resolving patch:
diff --git a/haystack/api/config.py b/haystack/api/config.py
--- a/haystack/api/config.py
+++ b/haystack/api/config.py
@@ -20,6 +20,7 @@
 ES_CONN_SCHEME = os.getenv("ES_CONN_SCHEME", "http")
 TEXT_FIELD_NAME = os.getenv("TEXT_FIELD_NAME", "text")
 SEARCH_FIELD_NAME = os.getenv("SEARCH_FIELD_NAME", "text")
+FAQ_QUESTION_FIELD_NAME = os.getenv("FAQ_QUESTION_FIELD_NAME", "question")
 EMBEDDING_FIELD_NAME = os.getenv("EMBEDDING_FIELD_NAME", None)
 EMBEDDING_DIM = os.getenv("EMBEDDING_DIM", None)
 
diff --git a/haystack/api/controller/search.py b/haystack/api/controller/search.py
--- a/haystack/api/controller/search.py
+++ b/haystack/api/controller/search.py
@@ -11,7 +11,7 @@
 from haystack.api.config import DB_HOST, DB_PORT, DB_USER, DB_PW, DB_INDEX, ES_CONN_SCHEME, TEXT_FIELD_NAME, SEARCH_FIELD_NAME, \
     EMBEDDING_DIM, EMBEDDING_FIELD_NAME, EXCLUDE_META_DATA_FIELDS, EMBEDDING_MODEL_PATH, USE_GPU, READER_MODEL_PATH, \
     BATCHSIZE, CONTEXT_WINDOW_SIZE, TOP_K_PER_CANDIDATE, NO_ANS_BOOST, MAX_PROCESSES, MAX_SEQ_LEN, DOC_STRIDE, \
-    DEFAULT_TOP_K_READER, DEFAULT_TOP_K_RETRIEVER, CONCURRENT_REQUEST_PER_WORKER
+    DEFAULT_TOP_K_READER, DEFAULT_TOP_K_RETRIEVER, CONCURRENT_REQUEST_PER_WORKER, FAQ_QUESTION_FIELD_NAME
 from haystack.api.controller.utils import RequestLimiter
 from haystack.database.elasticsearch import ElasticsearchDocumentStore
 from haystack.reader.farm import FARMReader
@@ -36,6 +36,7 @@
     embedding_dim=EMBEDDING_DIM,
     embedding_field=EMBEDDING_FIELD_NAME,
     excluded_meta_data=EXCLUDE_META_DATA_FIELDS,  # type: ignore
+    faq_question_field=FAQ_QUESTION_FIELD_NAME,
 )
 
 
diff --git a/haystack/database/elasticsearch.py b/haystack/database/elasticsearch.py
--- a/haystack/database/elasticsearch.py
+++ b/haystack/database/elasticsearch.py
@@ -26,6 +26,7 @@ def __init__(
         embedding_dim: Optional[str] = None,
         custom_mapping: Optional[dict] = None,
         excluded_meta_data: Optional[list] = None,
+        faq_question_field: Optional[str] = None,
         scheme: str = "http",
         ca_certs: bool = False,
         verify_certs: bool = True,
@@ -92,6 +93,7 @@ def __init__(
         self.external_source_id_field = external_source_id_field
         self.embedding_field = embedding_field
         self.excluded_meta_data = excluded_meta_data
+        self.faq_question_field = faq_question_field
 
     def get_document_by_id(self, id: str) -> Optional[Document]:
         query = {"query": {"ids": {"values": [id]}}}
@@ -227,6 +229,7 @@ def _convert_es_hit_to_document(self, hit: dict, score_adjustment: int = 0) -> D
             external_source_id=hit["_source"].get(self.external_source_id_field),
             meta=meta_data,
             query_score=hit["_score"] + score_adjustment if hit["_score"] else None,
+            question=hit["_source"].get(self.faq_question_field)
         )
         return document
 


Test patch: