Skip to content

Commit 31fa75e

Browse files
authored
feat: add support for Elasticsearch 7.16.2 (#3318)
* bump elastic to 7.16.2+ * decouple Elasticsearch and Opensearch use method override instead of func variables fix mypy default value fix broken tests update schema * relax version pin * rename the base class * rename module * fix import order * do not run the new tests in the old job * remove outdated TODO
1 parent 75641dd commit 31fa75e

File tree

9 files changed

+1864
-1791
lines changed

9 files changed

+1864
-1791
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ jobs:
315315
env:
316316
TOKENIZERS_PARALLELISM: 'false'
317317
run: |
318-
pytest ${{ env.PYTEST_PARAMS }} -m "opensearch and not integration" test/document_stores/ --document_store_type=opensearch
318+
pytest ${{ env.PYTEST_PARAMS }} -m "opensearch and not integration" test/document_stores/test_document_store.py --document_store_type=opensearch
319319
320320
- name: Dump docker logs on failure
321321
if: failure()

haystack/document_stores/elasticsearch.py

Lines changed: 418 additions & 1778 deletions
Large diffs are not rendered by default.

haystack/document_stores/opensearch.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
try:
1010
from opensearchpy import OpenSearch, Urllib3HttpConnection, RequestsHttpConnection, NotFoundError, RequestError
11-
from opensearchpy.helpers import bulk
11+
from opensearchpy.helpers import bulk, scan
1212
except (ImportError, ModuleNotFoundError) as e:
1313
from haystack.utils.import_utils import _optional_component_not_installed
1414

@@ -21,7 +21,7 @@
2121
from haystack.errors import DocumentStoreError
2222
from haystack.nodes.retriever import DenseRetriever
2323

24-
from .elasticsearch import BaseElasticsearchDocumentStore, prepare_hosts
24+
from .search_engine import SearchEngineDocumentStore, prepare_hosts
2525

2626
logger = logging.getLogger(__name__)
2727

@@ -35,7 +35,7 @@
3535
}
3636

3737

38-
class OpenSearchDocumentStore(BaseElasticsearchDocumentStore):
38+
class OpenSearchDocumentStore(SearchEngineDocumentStore):
3939
def __init__(
4040
self,
4141
scheme: str = "https", # Mind this different default param
@@ -208,6 +208,17 @@ def __init__(
208208
synonym_type=synonym_type,
209209
)
210210

211+
# Let the base class catch the right error from the Opensearch client
212+
self._RequestError = RequestError
213+
214+
def _do_bulk(self, *args, **kwargs):
215+
"""Override the base class method to use the Opensearch client"""
216+
return bulk(*args, **kwargs)
217+
218+
def _do_scan(self, *args, **kwargs):
219+
"""Override the base class method to use the Opensearch client"""
220+
return scan(*args, **kwargs)
221+
211222
@classmethod
212223
def _init_client(
213224
cls,

0 commit comments

Comments
 (0)