We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Embedding failed with large-nli-stsb model but work for base model
Trying to make use of the pre-trained model in sentence-transformer.  It works for base model (tried bert-base and roberta-base) but failed in large models (for roberta and I think bert as well) with the following errors at time of embedding corpus:

![image](https://user-images.githubusercontent.com/64902553/82432095-1f702e80-9ac2-11ea-86ad-60c9843717dd.png)

Seems like size of the embedding is too large to write as Elasticsearch index?

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `haystack/database/elasticsearch.py`
Content:
```
1 import json
2 import logging
3 from string import Template
4 
5 from elasticsearch import Elasticsearch
6 from elasticsearch.helpers import bulk, scan
7 
8 from haystack.database.base import BaseDocumentStore, Document
9 
10 logger = logging.getLogger(__name__)
11 
12 
13 class ElasticsearchDocumentStore(BaseDocumentStore):
14     def __init__(
15         self,
16         host="localhost",
17         username="",
18         password="",
19         index="document",
20         search_fields="text",
21         text_field="text",
22         name_field="name",
23         external_source_id_field="external_source_id",
24         tag_fields=None,
25         embedding_field=None,
26         embedding_dim=None,
27         custom_mapping=None,
28         excluded_meta_data=None,
29         scheme="http",
30         ca_certs=False,
31         verify_certs=True,
32         create_index=True
33     ):
34         self.client = Elasticsearch(hosts=[{"host": host}], http_auth=(username, password),
35                                     scheme=scheme, ca_certs=ca_certs, verify_certs=verify_certs)
36 
37         # if no custom_mapping is supplied, use the default mapping
38         if not custom_mapping:
39             custom_mapping = {
40                 "mappings": {
41                     "properties": {
42                         name_field: {"type": "text"},
43                         text_field: {"type": "text"},
44                         external_source_id_field: {"type": "text"},
45                     }
46                 }
47             }
48             if embedding_field:
49                 custom_mapping["mappings"]["properties"][embedding_field] = {"type": "dense_vector",
50                                                                              "dims": embedding_dim}
51         # create an index if not exists
52         if create_index:
53             self.client.indices.create(index=index, ignore=400, body=custom_mapping)
54         self.index = index
55 
56         # configure mappings to ES fields that will be used for querying / displaying results
57         if type(search_fields) == str:
58             search_fields = [search_fields]
59 
60         #TODO we should implement a more flexible interal mapping here that simplifies the usage of additional,
61         # custom fields (e.g. meta data you want to return)
62         self.search_fields = search_fields
63         self.text_field = text_field
64         self.name_field = name_field
65         self.tag_fields = tag_fields
66         self.external_source_id_field = external_source_id_field
67         self.embedding_field = embedding_field
68         self.excluded_meta_data = excluded_meta_data
69 
70     def get_document_by_id(self, id: str) -> Document:
71         query = {"query": {"ids": {"values": [id]}}}
72         result = self.client.search(index=self.index, body=query)["hits"]["hits"]
73 
74         document = self._convert_es_hit_to_document(result[0]) if result else None
75         return document
76 
77     def get_document_ids_by_tags(self, tags: dict) -> [str]:
78         term_queries = [{"terms": {key: value}} for key, value in tags.items()]
79         query = {"query": {"bool": {"must": term_queries}}}
80         logger.debug(f"Tag filter query: {query}")
81         result = self.client.search(index=self.index, body=query, size=10000)["hits"]["hits"]
82         doc_ids = []
83         for hit in result:
84             doc_ids.append(hit["_id"])
85         return doc_ids
86 
87     def write_documents(self, documents):
88         for doc in documents:
89             doc["_op_type"] = "create"
90             doc["_index"] = self.index
91 
92         bulk(self.client, documents)
93 
94     def get_document_count(self):
95         result = self.client.count()
96         count = result["count"]
97         return count
98 
99     def get_all_documents(self):
100         result = scan(self.client, query={"query": {"match_all": {}}}, index=self.index)
101         documents = [self._convert_es_hit_to_document(hit) for hit in result]
102 
103         return documents
104 
105     def query(
106         self,
107         query: str,
108         filters: dict = None,
109         top_k: int = 10,
110         custom_query: str = None,
111     ) -> [Document]:
112 
113         if custom_query:  # substitute placeholder for question and filters for the custom_query template string
114             template = Template(custom_query)
115 
116             substitutions = {"question": query}  # replace all "${question}" placeholder(s) with query
117             # replace all filter values placeholders with a list of strings(in JSON format) for each filter
118             if filters:
119                 for key, values in filters.items():
120                     values_str = json.dumps(values)
121                     substitutions[key] = values_str
122             custom_query_json = template.substitute(**substitutions)
123             body = json.loads(custom_query_json)
124         else:
125             body = {
126                 "size": top_k,
127                 "query": {
128                     "bool": {
129                         "should": [{"multi_match": {"query": query, "type": "most_fields", "fields": self.search_fields}}]
130                     }
131                 },
132             }
133 
134             if filters:
135                 filter_clause = []
136                 for key, values in filters.items():
137                     filter_clause.append(
138                         {
139                             "terms": {key: values}
140                         }
141                     )
142                 body["query"]["bool"]["filter"] = filter_clause
143 
144         if self.excluded_meta_data:
145             body["_source"] = {"excludes": self.excluded_meta_data}
146 
147         logger.debug(f"Retriever query: {body}")
148         result = self.client.search(index=self.index, body=body)["hits"]["hits"]
149 
150         documents = [self._convert_es_hit_to_document(hit) for hit in result]
151         return documents
152 
153     def query_by_embedding(self, query_emb, top_k=10, candidate_doc_ids=None) -> [Document]:
154         if not self.embedding_field:
155             raise RuntimeError("Please specify arg `embedding_field` in ElasticsearchDocumentStore()")
156         else:
157             # +1 in cosine similarity to avoid negative numbers
158             body= {
159                 "size": top_k,
160                 "query": {
161                     "script_score": {
162                         "query": {"match_all": {}},
163                         "script": {
164                             "source": f"cosineSimilarity(params.query_vector,doc['{self.embedding_field}']) + 1.0",
165                             "params": {
166                                 "query_vector": query_emb
167                             }
168                         }
169                     }
170                 }
171             }
172 
173             if candidate_doc_ids:
174                 body["query"]["script_score"]["query"] = {
175                     "bool": {
176                         "should": [{"match_all": {}}],
177                         "filter": [{"terms": {"_id": candidate_doc_ids}}]
178                 }}
179 
180             if self.excluded_meta_data:
181                 body["_source"] = {"excludes": self.excluded_meta_data}
182 
183             logger.debug(f"Retriever query: {body}")
184             result = self.client.search(index=self.index, body=body)["hits"]["hits"]
185 
186             documents = [self._convert_es_hit_to_document(hit, score_adjustment=-1) for hit in result]
187             return documents
188 
189     def _convert_es_hit_to_document(self, hit, score_adjustment=0) -> Document:
190         # We put all additional data of the doc into meta_data and return it in the API
191         meta_data = {k:v for k,v in hit["_source"].items() if k not in (self.text_field, self.external_source_id_field)}
192         meta_data["name"] = meta_data.pop(self.name_field, None)
193 
194         document = Document(
195             id=hit["_id"],
196             text=hit["_source"][self.text_field],
197             external_source_id=hit["_source"].get(self.external_source_id_field),
198             meta=meta_data,
199             query_score=hit["_score"] + score_adjustment if hit["_score"] else None,
200         )
201         return document
202
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/haystack/database/elasticsearch.py b/haystack/database/elasticsearch.py
--- a/haystack/database/elasticsearch.py
+++ b/haystack/database/elasticsearch.py
@@ -89,7 +89,7 @@
             doc["_op_type"] = "create"
             doc["_index"] = self.index
 
-        bulk(self.client, documents)
+        bulk(self.client, documents, request_timeout=30)
 
     def get_document_count(self):
         result = self.client.count()

{"golden_diff": "diff --git a/haystack/database/elasticsearch.py b/haystack/database/elasticsearch.py\n--- a/haystack/database/elasticsearch.py\n+++ b/haystack/database/elasticsearch.py\n@@ -89,7 +89,7 @@\n             doc[\"_op_type\"] = \"create\"\n             doc[\"_index\"] = self.index\n \n-        bulk(self.client, documents)\n+        bulk(self.client, documents, request_timeout=30)\n \n     def get_document_count(self):\n         result = self.client.count()\n", "issue": "Embedding failed with large-nli-stsb model but work for base model\nTrying to make use of the pre-trained model in sentence-transformer.  It works for base model (tried bert-base and roberta-base) but failed in large models (for roberta and I think bert as well) with the following errors at time of embedding corpus:\r\n\r\n![image](https://user-images.githubusercontent.com/64902553/82432095-1f702e80-9ac2-11ea-86ad-60c9843717dd.png)\r\n\r\nSeems like size of the embedding is too large to write as Elasticsearch index?\n", "before_files": [{"content": "import json\nimport logging\nfrom string import Template\n\nfrom elasticsearch import Elasticsearch\nfrom elasticsearch.helpers import bulk, scan\n\nfrom haystack.database.base import BaseDocumentStore, Document\n\nlogger = logging.getLogger(__name__)\n\n\nclass ElasticsearchDocumentStore(BaseDocumentStore):\n    def __init__(\n        self,\n        host=\"localhost\",\n        username=\"\",\n        password=\"\",\n        index=\"document\",\n        search_fields=\"text\",\n        text_field=\"text\",\n        name_field=\"name\",\n        external_source_id_field=\"external_source_id\",\n        tag_fields=None,\n        embedding_field=None,\n        embedding_dim=None,\n        custom_mapping=None,\n        excluded_meta_data=None,\n        scheme=\"http\",\n        ca_certs=False,\n        verify_certs=True,\n        create_index=True\n    ):\n        self.client = Elasticsearch(hosts=[{\"host\": host}], http_auth=(username, password),\n                                    scheme=scheme, ca_certs=ca_certs, verify_certs=verify_certs)\n\n        # if no custom_mapping is supplied, use the default mapping\n        if not custom_mapping:\n            custom_mapping = {\n                \"mappings\": {\n                    \"properties\": {\n                        name_field: {\"type\": \"text\"},\n                        text_field: {\"type\": \"text\"},\n                        external_source_id_field: {\"type\": \"text\"},\n                    }\n                }\n            }\n            if embedding_field:\n                custom_mapping[\"mappings\"][\"properties\"][embedding_field] = {\"type\": \"dense_vector\",\n                                                                             \"dims\": embedding_dim}\n        # create an index if not exists\n        if create_index:\n            self.client.indices.create(index=index, ignore=400, body=custom_mapping)\n        self.index = index\n\n        # configure mappings to ES fields that will be used for querying / displaying results\n        if type(search_fields) == str:\n            search_fields = [search_fields]\n\n        #TODO we should implement a more flexible interal mapping here that simplifies the usage of additional,\n        # custom fields (e.g. meta data you want to return)\n        self.search_fields = search_fields\n        self.text_field = text_field\n        self.name_field = name_field\n        self.tag_fields = tag_fields\n        self.external_source_id_field = external_source_id_field\n        self.embedding_field = embedding_field\n        self.excluded_meta_data = excluded_meta_data\n\n    def get_document_by_id(self, id: str) -> Document:\n        query = {\"query\": {\"ids\": {\"values\": [id]}}}\n        result = self.client.search(index=self.index, body=query)[\"hits\"][\"hits\"]\n\n        document = self._convert_es_hit_to_document(result[0]) if result else None\n        return document\n\n    def get_document_ids_by_tags(self, tags: dict) -> [str]:\n        term_queries = [{\"terms\": {key: value}} for key, value in tags.items()]\n        query = {\"query\": {\"bool\": {\"must\": term_queries}}}\n        logger.debug(f\"Tag filter query: {query}\")\n        result = self.client.search(index=self.index, body=query, size=10000)[\"hits\"][\"hits\"]\n        doc_ids = []\n        for hit in result:\n            doc_ids.append(hit[\"_id\"])\n        return doc_ids\n\n    def write_documents(self, documents):\n        for doc in documents:\n            doc[\"_op_type\"] = \"create\"\n            doc[\"_index\"] = self.index\n\n        bulk(self.client, documents)\n\n    def get_document_count(self):\n        result = self.client.count()\n        count = result[\"count\"]\n        return count\n\n    def get_all_documents(self):\n        result = scan(self.client, query={\"query\": {\"match_all\": {}}}, index=self.index)\n        documents = [self._convert_es_hit_to_document(hit) for hit in result]\n\n        return documents\n\n    def query(\n        self,\n        query: str,\n        filters: dict = None,\n        top_k: int = 10,\n        custom_query: str = None,\n    ) -> [Document]:\n\n        if custom_query:  # substitute placeholder for question and filters for the custom_query template string\n            template = Template(custom_query)\n\n            substitutions = {\"question\": query}  # replace all \"${question}\" placeholder(s) with query\n            # replace all filter values placeholders with a list of strings(in JSON format) for each filter\n            if filters:\n                for key, values in filters.items():\n                    values_str = json.dumps(values)\n                    substitutions[key] = values_str\n            custom_query_json = template.substitute(**substitutions)\n            body = json.loads(custom_query_json)\n        else:\n            body = {\n                \"size\": top_k,\n                \"query\": {\n                    \"bool\": {\n                        \"should\": [{\"multi_match\": {\"query\": query, \"type\": \"most_fields\", \"fields\": self.search_fields}}]\n                    }\n                },\n            }\n\n            if filters:\n                filter_clause = []\n                for key, values in filters.items():\n                    filter_clause.append(\n                        {\n                            \"terms\": {key: values}\n                        }\n                    )\n                body[\"query\"][\"bool\"][\"filter\"] = filter_clause\n\n        if self.excluded_meta_data:\n            body[\"_source\"] = {\"excludes\": self.excluded_meta_data}\n\n        logger.debug(f\"Retriever query: {body}\")\n        result = self.client.search(index=self.index, body=body)[\"hits\"][\"hits\"]\n\n        documents = [self._convert_es_hit_to_document(hit) for hit in result]\n        return documents\n\n    def query_by_embedding(self, query_emb, top_k=10, candidate_doc_ids=None) -> [Document]:\n        if not self.embedding_field:\n            raise RuntimeError(\"Please specify arg `embedding_field` in ElasticsearchDocumentStore()\")\n        else:\n            # +1 in cosine similarity to avoid negative numbers\n            body= {\n                \"size\": top_k,\n                \"query\": {\n                    \"script_score\": {\n                        \"query\": {\"match_all\": {}},\n                        \"script\": {\n                            \"source\": f\"cosineSimilarity(params.query_vector,doc['{self.embedding_field}']) + 1.0\",\n                            \"params\": {\n                                \"query_vector\": query_emb\n                            }\n                        }\n                    }\n                }\n            }\n\n            if candidate_doc_ids:\n                body[\"query\"][\"script_score\"][\"query\"] = {\n                    \"bool\": {\n                        \"should\": [{\"match_all\": {}}],\n                        \"filter\": [{\"terms\": {\"_id\": candidate_doc_ids}}]\n                }}\n\n            if self.excluded_meta_data:\n                body[\"_source\"] = {\"excludes\": self.excluded_meta_data}\n\n            logger.debug(f\"Retriever query: {body}\")\n            result = self.client.search(index=self.index, body=body)[\"hits\"][\"hits\"]\n\n            documents = [self._convert_es_hit_to_document(hit, score_adjustment=-1) for hit in result]\n            return documents\n\n    def _convert_es_hit_to_document(self, hit, score_adjustment=0) -> Document:\n        # We put all additional data of the doc into meta_data and return it in the API\n        meta_data = {k:v for k,v in hit[\"_source\"].items() if k not in (self.text_field, self.external_source_id_field)}\n        meta_data[\"name\"] = meta_data.pop(self.name_field, None)\n\n        document = Document(\n            id=hit[\"_id\"],\n            text=hit[\"_source\"][self.text_field],\n            external_source_id=hit[\"_source\"].get(self.external_source_id_field),\n            meta=meta_data,\n            query_score=hit[\"_score\"] + score_adjustment if hit[\"_score\"] else None,\n        )\n        return document\n", "path": "haystack/database/elasticsearch.py"}], "after_files": [{"content": "import json\nimport logging\nfrom string import Template\n\nfrom elasticsearch import Elasticsearch\nfrom elasticsearch.helpers import bulk, scan\n\nfrom haystack.database.base import BaseDocumentStore, Document\n\nlogger = logging.getLogger(__name__)\n\n\nclass ElasticsearchDocumentStore(BaseDocumentStore):\n    def __init__(\n        self,\n        host=\"localhost\",\n        username=\"\",\n        password=\"\",\n        index=\"document\",\n        search_fields=\"text\",\n        text_field=\"text\",\n        name_field=\"name\",\n        external_source_id_field=\"external_source_id\",\n        tag_fields=None,\n        embedding_field=None,\n        embedding_dim=None,\n        custom_mapping=None,\n        excluded_meta_data=None,\n        scheme=\"http\",\n        ca_certs=False,\n        verify_certs=True,\n        create_index=True\n    ):\n        self.client = Elasticsearch(hosts=[{\"host\": host}], http_auth=(username, password),\n                                    scheme=scheme, ca_certs=ca_certs, verify_certs=verify_certs)\n\n        # if no custom_mapping is supplied, use the default mapping\n        if not custom_mapping:\n            custom_mapping = {\n                \"mappings\": {\n                    \"properties\": {\n                        name_field: {\"type\": \"text\"},\n                        text_field: {\"type\": \"text\"},\n                        external_source_id_field: {\"type\": \"text\"},\n                    }\n                }\n            }\n            if embedding_field:\n                custom_mapping[\"mappings\"][\"properties\"][embedding_field] = {\"type\": \"dense_vector\",\n                                                                             \"dims\": embedding_dim}\n        # create an index if not exists\n        if create_index:\n            self.client.indices.create(index=index, ignore=400, body=custom_mapping)\n        self.index = index\n\n        # configure mappings to ES fields that will be used for querying / displaying results\n        if type(search_fields) == str:\n            search_fields = [search_fields]\n\n        #TODO we should implement a more flexible interal mapping here that simplifies the usage of additional,\n        # custom fields (e.g. meta data you want to return)\n        self.search_fields = search_fields\n        self.text_field = text_field\n        self.name_field = name_field\n        self.tag_fields = tag_fields\n        self.external_source_id_field = external_source_id_field\n        self.embedding_field = embedding_field\n        self.excluded_meta_data = excluded_meta_data\n\n    def get_document_by_id(self, id: str) -> Document:\n        query = {\"query\": {\"ids\": {\"values\": [id]}}}\n        result = self.client.search(index=self.index, body=query)[\"hits\"][\"hits\"]\n\n        document = self._convert_es_hit_to_document(result[0]) if result else None\n        return document\n\n    def get_document_ids_by_tags(self, tags: dict) -> [str]:\n        term_queries = [{\"terms\": {key: value}} for key, value in tags.items()]\n        query = {\"query\": {\"bool\": {\"must\": term_queries}}}\n        logger.debug(f\"Tag filter query: {query}\")\n        result = self.client.search(index=self.index, body=query, size=10000)[\"hits\"][\"hits\"]\n        doc_ids = []\n        for hit in result:\n            doc_ids.append(hit[\"_id\"])\n        return doc_ids\n\n    def write_documents(self, documents):\n        for doc in documents:\n            doc[\"_op_type\"] = \"create\"\n            doc[\"_index\"] = self.index\n\n        bulk(self.client, documents, request_timeout=30)\n\n    def get_document_count(self):\n        result = self.client.count()\n        count = result[\"count\"]\n        return count\n\n    def get_all_documents(self):\n        result = scan(self.client, query={\"query\": {\"match_all\": {}}}, index=self.index)\n        documents = [self._convert_es_hit_to_document(hit) for hit in result]\n\n        return documents\n\n    def query(\n        self,\n        query: str,\n        filters: dict = None,\n        top_k: int = 10,\n        custom_query: str = None,\n    ) -> [Document]:\n\n        if custom_query:  # substitute placeholder for question and filters for the custom_query template string\n            template = Template(custom_query)\n\n            substitutions = {\"question\": query}  # replace all \"${question}\" placeholder(s) with query\n            # replace all filter values placeholders with a list of strings(in JSON format) for each filter\n            if filters:\n                for key, values in filters.items():\n                    values_str = json.dumps(values)\n                    substitutions[key] = values_str\n            custom_query_json = template.substitute(**substitutions)\n            body = json.loads(custom_query_json)\n        else:\n            body = {\n                \"size\": top_k,\n                \"query\": {\n                    \"bool\": {\n                        \"should\": [{\"multi_match\": {\"query\": query, \"type\": \"most_fields\", \"fields\": self.search_fields}}]\n                    }\n                },\n            }\n\n            if filters:\n                filter_clause = []\n                for key, values in filters.items():\n                    filter_clause.append(\n                        {\n                            \"terms\": {key: values}\n                        }\n                    )\n                body[\"query\"][\"bool\"][\"filter\"] = filter_clause\n\n        if self.excluded_meta_data:\n            body[\"_source\"] = {\"excludes\": self.excluded_meta_data}\n\n        logger.debug(f\"Retriever query: {body}\")\n        result = self.client.search(index=self.index, body=body)[\"hits\"][\"hits\"]\n\n        documents = [self._convert_es_hit_to_document(hit) for hit in result]\n        return documents\n\n    def query_by_embedding(self, query_emb, top_k=10, candidate_doc_ids=None) -> [Document]:\n        if not self.embedding_field:\n            raise RuntimeError(\"Please specify arg `embedding_field` in ElasticsearchDocumentStore()\")\n        else:\n            # +1 in cosine similarity to avoid negative numbers\n            body= {\n                \"size\": top_k,\n                \"query\": {\n                    \"script_score\": {\n                        \"query\": {\"match_all\": {}},\n                        \"script\": {\n                            \"source\": f\"cosineSimilarity(params.query_vector,doc['{self.embedding_field}']) + 1.0\",\n                            \"params\": {\n                                \"query_vector\": query_emb\n                            }\n                        }\n                    }\n                }\n            }\n\n            if candidate_doc_ids:\n                body[\"query\"][\"script_score\"][\"query\"] = {\n                    \"bool\": {\n                        \"should\": [{\"match_all\": {}}],\n                        \"filter\": [{\"terms\": {\"_id\": candidate_doc_ids}}]\n                }}\n\n            if self.excluded_meta_data:\n                body[\"_source\"] = {\"excludes\": self.excluded_meta_data}\n\n            logger.debug(f\"Retriever query: {body}\")\n            result = self.client.search(index=self.index, body=body)[\"hits\"][\"hits\"]\n\n            documents = [self._convert_es_hit_to_document(hit, score_adjustment=-1) for hit in result]\n            return documents\n\n    def _convert_es_hit_to_document(self, hit, score_adjustment=0) -> Document:\n        # We put all additional data of the doc into meta_data and return it in the API\n        meta_data = {k:v for k,v in hit[\"_source\"].items() if k not in (self.text_field, self.external_source_id_field)}\n        meta_data[\"name\"] = meta_data.pop(self.name_field, None)\n\n        document = Document(\n            id=hit[\"_id\"],\n            text=hit[\"_source\"][self.text_field],\n            external_source_id=hit[\"_source\"].get(self.external_source_id_field),\n            meta=meta_data,\n            query_score=hit[\"_score\"] + score_adjustment if hit[\"_score\"] else None,\n        )\n        return document\n", "path": "haystack/database/elasticsearch.py"}]}