From 8f6c5fd178df4dac6c3e6c28394b11495feb674c Mon Sep 17 00:00:00 2001 From: Thomas Binsfeld Date: Tue, 29 Jul 2025 08:50:15 +0200 Subject: [PATCH] [REF] connector_elasticsearch: elasticsearch v8 compatibility --- connector_elasticsearch/README.rst | 13 +++-- connector_elasticsearch/__manifest__.py | 10 +++- .../i18n/connector_elasticsearch.pot | 16 ----- connector_elasticsearch/i18n/it.po | 16 ----- connector_elasticsearch/models/se_backend.py | 5 -- .../readme/CONTRIBUTORS.rst | 1 + connector_elasticsearch/readme/HISTORY.rst | 6 ++ .../static/description/index.html | 49 ++++++++-------- ...ectorElasticsearch.test_index_adapter.yaml | 4 +- ...asticsearch.test_index_adapter_delete.yaml | 20 ++++++- ..._adapter_delete_nonexisting_documents.yaml | 4 +- ...Elasticsearch.test_index_adapter_iter.yaml | 16 ++++- ...sticsearch.test_index_adapter_reindex.yaml | 34 ++++++++++- .../tests/test_connector_elasticsearch.py | 4 +- connector_elasticsearch/tools/adapter.py | 58 ++++++++++--------- connector_elasticsearch/views/se_backend.xml | 5 -- requirements.txt | 3 +- 17 files changed, 156 insertions(+), 108 deletions(-) diff --git a/connector_elasticsearch/README.rst b/connector_elasticsearch/README.rst index 3d1dae4f..c0db2e45 100644 --- a/connector_elasticsearch/README.rst +++ b/connector_elasticsearch/README.rst @@ -1,7 +1,3 @@ -.. image:: https://odoo-community.org/readme-banner-image - :target: https://odoo-community.org/get-involved?utm_source=readme - :alt: Odoo Community Association - ======================= connector_elasticsearch ======================= @@ -17,7 +13,7 @@ connector_elasticsearch .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png :target: https://odoo-community.org/page/development-status :alt: Beta -.. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsearch--engine-lightgray.png?logo=github @@ -45,6 +41,12 @@ Elasticsearch_ indexes. Changelog ========= +16.0.0.3.0 +~~~~~~~~~~ + +* elasticsearch v8 compatibility: The connector now supports Elasticsearch + v8.*.* versions. + 12.0.?.?.? (unreleased) ~~~~~~~~~~~~~~~~~~~~~~~ @@ -78,6 +80,7 @@ Contributors * Raphaël Reverdy * Simone Orsi * Iván Todorovich +* Thomas Binsfeld Maintainers ~~~~~~~~~~~ diff --git a/connector_elasticsearch/__manifest__.py b/connector_elasticsearch/__manifest__.py index fd0ba89d..d784cc02 100644 --- a/connector_elasticsearch/__manifest__.py +++ b/connector_elasticsearch/__manifest__.py @@ -5,7 +5,7 @@ "name": "connector_elasticsearch", "category": "Connector", "summary": "Connector For Elasticsearch Search Engine", - "version": "16.0.0.2.2", + "version": "16.0.0.3.0", "license": "AGPL-3", "author": "ACSONE SA/NV, Odoo Community Association (OCA)", "website": "https://github.com/OCA/search-engine", @@ -15,6 +15,12 @@ ], "demo": ["demo/backend_demo.xml"], # TODO: Get latest improvements from elasticsearch library - "external_dependencies": {"python": ["elasticsearch>=7.0.0,<=7.13.4", "requests"]}, + "external_dependencies": { + "python": [ + "elasticsearch>=8.0.0,<9.0.0", + "elastic-transport>=8.15.1,<9.0.0", + "requests", + ] + }, "installable": True, } diff --git a/connector_elasticsearch/i18n/connector_elasticsearch.pot b/connector_elasticsearch/i18n/connector_elasticsearch.pot index 7643c04f..9b8445f5 100644 --- a/connector_elasticsearch/i18n/connector_elasticsearch.pot +++ b/connector_elasticsearch/i18n/connector_elasticsearch.pot @@ -141,11 +141,6 @@ msgstr "" msgid "Retry on timeout" msgstr "" -#. module: connector_elasticsearch -#: model_terms:ir.ui.view,arch_db:connector_elasticsearch.se_backend_form_view -msgid "SSL" -msgstr "" - #. module: connector_elasticsearch #: model:ir.model,name:connector_elasticsearch.model_se_backend msgid "Se Backend" @@ -156,11 +151,6 @@ msgstr "" msgid "Se Index" msgstr "" -#. module: connector_elasticsearch -#: model:ir.model.fields,field_description:connector_elasticsearch.field_se_backend__ssl -msgid "Ssl" -msgstr "" - #. module: connector_elasticsearch #: model_terms:ir.ui.view,arch_db:connector_elasticsearch.se_backend_form_view msgid "Timeout" @@ -218,12 +208,6 @@ msgstr "" msgid "User" msgstr "" -#. module: connector_elasticsearch -#: model:ir.model.fields,help:connector_elasticsearch.field_se_backend__ssl -msgid "" -"Verify SSL certificates. Only set to False in development environments." -msgstr "" - #. module: connector_elasticsearch #: model_terms:ir.ui.view,arch_db:connector_elasticsearch.se_backend_form_view msgid "http://elastic:9200" diff --git a/connector_elasticsearch/i18n/it.po b/connector_elasticsearch/i18n/it.po index a0e9e798..cf4ff6f2 100644 --- a/connector_elasticsearch/i18n/it.po +++ b/connector_elasticsearch/i18n/it.po @@ -148,11 +148,6 @@ msgstr "Password" msgid "Retry on timeout" msgstr "Ritenta al timeout" -#. module: connector_elasticsearch -#: model_terms:ir.ui.view,arch_db:connector_elasticsearch.se_backend_form_view -msgid "SSL" -msgstr "SSL" - #. module: connector_elasticsearch #: model:ir.model,name:connector_elasticsearch.model_se_backend msgid "Se Backend" @@ -163,11 +158,6 @@ msgstr "Backend SE" msgid "Se Index" msgstr "Indice SE" -#. module: connector_elasticsearch -#: model:ir.model.fields,field_description:connector_elasticsearch.field_se_backend__ssl -msgid "Ssl" -msgstr "SSL" - #. module: connector_elasticsearch #: model_terms:ir.ui.view,arch_db:connector_elasticsearch.se_backend_form_view msgid "Timeout" @@ -228,12 +218,6 @@ msgstr "Impossibile contattare l'host." msgid "User" msgstr "Utente" -#. module: connector_elasticsearch -#: model:ir.model.fields,help:connector_elasticsearch.field_se_backend__ssl -msgid "Verify SSL certificates. Only set to False in development environments." -msgstr "" -"Verifica certificati SSL. Impostare a False solo in ambienti di sviluppo." - #. module: connector_elasticsearch #: model_terms:ir.ui.view,arch_db:connector_elasticsearch.se_backend_form_view msgid "http://elastic:9200" diff --git a/connector_elasticsearch/models/se_backend.py b/connector_elasticsearch/models/se_backend.py index e826132e..b1cd6f66 100644 --- a/connector_elasticsearch/models/se_backend.py +++ b/connector_elasticsearch/models/se_backend.py @@ -33,10 +33,6 @@ class SeBackend(models.Model): ) es_user = fields.Char(help="Leave blank if not using http authentication.") es_password = fields.Char(help="Leave blank if not using http authentication.") - ssl = fields.Boolean( - default=True, - help="Verify SSL certificates. Only set to False in development environments.", - ) es_timeout = fields.Integer( string="Elasticsearch timeout", default=10, @@ -63,7 +59,6 @@ def _server_env_fields(self): "auth_type": {}, "es_user": {}, "es_password": {}, - "ssl": {}, "api_key_id": {}, "api_key": {}, } diff --git a/connector_elasticsearch/readme/CONTRIBUTORS.rst b/connector_elasticsearch/readme/CONTRIBUTORS.rst index 17e53e82..83cc8efe 100644 --- a/connector_elasticsearch/readme/CONTRIBUTORS.rst +++ b/connector_elasticsearch/readme/CONTRIBUTORS.rst @@ -3,3 +3,4 @@ * Raphaël Reverdy * Simone Orsi * Iván Todorovich +* Thomas Binsfeld diff --git a/connector_elasticsearch/readme/HISTORY.rst b/connector_elasticsearch/readme/HISTORY.rst index 22a930af..64ca2ace 100644 --- a/connector_elasticsearch/readme/HISTORY.rst +++ b/connector_elasticsearch/readme/HISTORY.rst @@ -1,3 +1,9 @@ +16.0.0.3.0 +~~~~~~~~~~ + +* elasticsearch v8 compatibility: The connector now supports Elasticsearch + v8.*.* versions. + 12.0.?.?.? (unreleased) ~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/connector_elasticsearch/static/description/index.html b/connector_elasticsearch/static/description/index.html index f70680b9..37fe819b 100644 --- a/connector_elasticsearch/static/description/index.html +++ b/connector_elasticsearch/static/description/index.html @@ -3,7 +3,7 @@ -README.rst +connector_elasticsearch -
+
+

connector_elasticsearch

- - -Odoo Community Association - -
-

connector_elasticsearch

-

Beta License: AGPL-3 OCA/search-engine Translate me on Weblate Try me on Runboat

+

Beta License: AGPL-3 OCA/search-engine Translate me on Weblate Try me on Runboat

This addon provides the bases to implement addons to export information to Elasticsearch indexes.

Table of contents

-

Changelog

+

Changelog

+
+

16.0.0.3.0

+
    +
  • elasticsearch v8 compatibility: The connector now supports Elasticsearch +v8.*.* versions.
  • +
+
-

12.0.?.?.? (unreleased)

+

12.0.?.?.? (unreleased)

  • connector_elasticsearch: Makes the config on index required only if the index is linked to an elastisearch backend. This change allows the usage @@ -405,7 +408,7 @@

    12.0.?.?.? (unreleased)

-

Bug Tracker

+

Bug Tracker

Bugs are tracked on GitHub Issues. In case of trouble, please check there if your issue has already been reported. If you spotted it first, help us to smash it by providing a detailed and welcomed @@ -413,25 +416,26 @@

Bug Tracker

Do not contact contributors directly about support or help with technical issues.

-

Credits

+

Credits

-

Authors

+

Authors

  • ACSONE SA/NV
-

Maintainers

+

Maintainers

This module is maintained by the OCA.

Odoo Community Association @@ -444,6 +448,5 @@

Maintainers

-
diff --git a/connector_elasticsearch/tests/cassettes/TestConnectorElasticsearch.test_index_adapter.yaml b/connector_elasticsearch/tests/cassettes/TestConnectorElasticsearch.test_index_adapter.yaml index 42cdfa86..08b3770d 100644 --- a/connector_elasticsearch/tests/cassettes/TestConnectorElasticsearch.test_index_adapter.yaml +++ b/connector_elasticsearch/tests/cassettes/TestConnectorElasticsearch.test_index_adapter.yaml @@ -14,7 +14,7 @@ interactions: - elasticsearch-py/7.13.4 (Python 3.10.6) x-elastic-client-meta: - es=7.13.4,py=3.10.6,t=7.13.4,rq=2.28.2,h=bp - method: POST + method: PUT uri: http://elastic:9200/_bulk response: body: @@ -24,6 +24,8 @@ interactions: - '252' content-type: - application/json; charset=UTF-8 + x-elastic-product: + - Elasticsearch status: code: 200 message: OK diff --git a/connector_elasticsearch/tests/cassettes/TestConnectorElasticsearch.test_index_adapter_delete.yaml b/connector_elasticsearch/tests/cassettes/TestConnectorElasticsearch.test_index_adapter_delete.yaml index d978b17d..f63b42f1 100644 --- a/connector_elasticsearch/tests/cassettes/TestConnectorElasticsearch.test_index_adapter_delete.yaml +++ b/connector_elasticsearch/tests/cassettes/TestConnectorElasticsearch.test_index_adapter_delete.yaml @@ -18,6 +18,8 @@ interactions: - '106' content-type: - application/json; charset=UTF-8 + x-elastic-product: + - Elasticsearch status: code: 200 message: OK @@ -42,6 +44,8 @@ interactions: - '21' content-type: - application/json; charset=UTF-8 + x-elastic-product: + - Elasticsearch status: code: 200 message: OK @@ -64,6 +68,8 @@ interactions: - '569' content-type: - application/json; charset=UTF-8 + x-elastic-product: + - Elasticsearch status: code: 404 message: Not Found @@ -88,6 +94,8 @@ interactions: - '101' content-type: - application/json; charset=UTF-8 + x-elastic-product: + - Elasticsearch status: code: 200 message: OK @@ -112,6 +120,8 @@ interactions: - '21' content-type: - application/json; charset=UTF-8 + x-elastic-product: + - Elasticsearch status: code: 200 message: OK @@ -138,7 +148,7 @@ interactions: - elasticsearch-py/7.13.4 (Python 3.10.6) x-elastic-client-meta: - es=7.13.4,py=3.10.6,t=7.13.4,rq=2.28.2,h=bp - method: POST + method: PUT uri: http://elastic:9200/_bulk response: body: @@ -148,6 +158,8 @@ interactions: - '686' content-type: - application/json; charset=UTF-8 + x-elastic-product: + - Elasticsearch status: code: 200 message: OK @@ -166,7 +178,7 @@ interactions: - elasticsearch-py/7.13.4 (Python 3.10.6) x-elastic-client-meta: - es=7.13.4,py=3.10.6,t=7.13.4,rq=2.28.2,h=bp - method: POST + method: PUT uri: http://elastic:9200/_bulk response: body: @@ -176,6 +188,8 @@ interactions: - '471' content-type: - application/json; charset=UTF-8 + x-elastic-product: + - Elasticsearch status: code: 200 message: OK @@ -200,6 +214,8 @@ interactions: - '45' content-type: - application/json; charset=UTF-8 + x-elastic-product: + - Elasticsearch status: code: 200 message: OK diff --git a/connector_elasticsearch/tests/cassettes/TestConnectorElasticsearch.test_index_adapter_delete_nonexisting_documents.yaml b/connector_elasticsearch/tests/cassettes/TestConnectorElasticsearch.test_index_adapter_delete_nonexisting_documents.yaml index e8fc8ff3..aca1d0a9 100644 --- a/connector_elasticsearch/tests/cassettes/TestConnectorElasticsearch.test_index_adapter_delete_nonexisting_documents.yaml +++ b/connector_elasticsearch/tests/cassettes/TestConnectorElasticsearch.test_index_adapter_delete_nonexisting_documents.yaml @@ -14,7 +14,7 @@ interactions: - elasticsearch-py/7.13.4 (Python 3.10.6) x-elastic-client-meta: - es=7.13.4,py=3.10.6,t=7.13.4,rq=2.28.2,h=bp - method: POST + method: PUT uri: http://elastic:9200/_bulk response: body: @@ -24,6 +24,8 @@ interactions: - '494' content-type: - application/json; charset=UTF-8 + x-elastic-product: + - Elasticsearch status: code: 200 message: OK diff --git a/connector_elasticsearch/tests/cassettes/TestConnectorElasticsearch.test_index_adapter_iter.yaml b/connector_elasticsearch/tests/cassettes/TestConnectorElasticsearch.test_index_adapter_iter.yaml index 49508a1b..dd8e956e 100644 --- a/connector_elasticsearch/tests/cassettes/TestConnectorElasticsearch.test_index_adapter_iter.yaml +++ b/connector_elasticsearch/tests/cassettes/TestConnectorElasticsearch.test_index_adapter_iter.yaml @@ -18,6 +18,8 @@ interactions: - '106' content-type: - application/json; charset=UTF-8 + x-elastic-product: + - Elasticsearch status: code: 200 message: OK @@ -42,6 +44,8 @@ interactions: - '21' content-type: - application/json; charset=UTF-8 + x-elastic-product: + - Elasticsearch status: code: 200 message: OK @@ -64,6 +68,8 @@ interactions: - '569' content-type: - application/json; charset=UTF-8 + x-elastic-product: + - Elasticsearch status: code: 404 message: Not Found @@ -88,6 +94,8 @@ interactions: - '101' content-type: - application/json; charset=UTF-8 + x-elastic-product: + - Elasticsearch status: code: 200 message: OK @@ -112,6 +120,8 @@ interactions: - '21' content-type: - application/json; charset=UTF-8 + x-elastic-product: + - Elasticsearch status: code: 200 message: OK @@ -138,7 +148,7 @@ interactions: - elasticsearch-py/7.13.4 (Python 3.10.6) x-elastic-client-meta: - es=7.13.4,py=3.10.6,t=7.13.4,rq=2.28.2,h=bp - method: POST + method: PUT uri: http://elastic:9200/_bulk response: body: @@ -148,6 +158,8 @@ interactions: - '686' content-type: - application/json; charset=UTF-8 + x-elastic-product: + - Elasticsearch status: code: 200 message: OK @@ -172,6 +184,8 @@ interactions: - '96' content-type: - application/json; charset=UTF-8 + x-elastic-product: + - Elasticsearch status: code: 200 message: OK diff --git a/connector_elasticsearch/tests/cassettes/TestConnectorElasticsearch.test_index_adapter_reindex.yaml b/connector_elasticsearch/tests/cassettes/TestConnectorElasticsearch.test_index_adapter_reindex.yaml index 51371549..478a2029 100644 --- a/connector_elasticsearch/tests/cassettes/TestConnectorElasticsearch.test_index_adapter_reindex.yaml +++ b/connector_elasticsearch/tests/cassettes/TestConnectorElasticsearch.test_index_adapter_reindex.yaml @@ -18,6 +18,8 @@ interactions: - '106' content-type: - application/json; charset=UTF-8 + x-elastic-product: + - Elasticsearch status: code: 200 message: OK @@ -42,6 +44,8 @@ interactions: - '21' content-type: - application/json; charset=UTF-8 + x-elastic-product: + - Elasticsearch status: code: 200 message: OK @@ -64,6 +68,8 @@ interactions: - '569' content-type: - application/json; charset=UTF-8 + x-elastic-product: + - Elasticsearch status: code: 404 message: Not Found @@ -88,6 +94,8 @@ interactions: - '101' content-type: - application/json; charset=UTF-8 + x-elastic-product: + - Elasticsearch status: code: 200 message: OK @@ -112,6 +120,8 @@ interactions: - '21' content-type: - application/json; charset=UTF-8 + x-elastic-product: + - Elasticsearch status: code: 200 message: OK @@ -138,7 +148,7 @@ interactions: - elasticsearch-py/7.13.4 (Python 3.10.6) x-elastic-client-meta: - es=7.13.4,py=3.10.6,t=7.13.4,rq=2.28.2,h=bp - method: POST + method: PUT uri: http://elastic:9200/_bulk response: body: @@ -148,6 +158,8 @@ interactions: - '686' content-type: - application/json; charset=UTF-8 + x-elastic-product: + - Elasticsearch status: code: 200 message: OK @@ -170,6 +182,8 @@ interactions: - '106' content-type: - application/json; charset=UTF-8 + x-elastic-product: + - Elasticsearch status: code: 200 message: OK @@ -192,6 +206,8 @@ interactions: - '106' content-type: - application/json; charset=UTF-8 + x-elastic-product: + - Elasticsearch status: code: 200 message: OK @@ -216,6 +232,8 @@ interactions: - '101' content-type: - application/json; charset=UTF-8 + x-elastic-product: + - Elasticsearch status: code: 200 message: OK @@ -231,7 +249,7 @@ interactions: x-elastic-client-meta: - es=7.13.4,py=3.10.6,t=7.13.4,rq=2.28.2 method: POST - uri: http://elastic:9200/_reindex?wait_for_completion=false + uri: http://elastic:9200/_reindex?timeout=9999999&wait_for_completion=false response: body: string: '{"task":"Ch4zlGppTF-9rtPxsPpYeQ:1982"}' @@ -240,6 +258,8 @@ interactions: - '38' content-type: - application/json; charset=UTF-8 + x-elastic-product: + - Elasticsearch status: code: 200 message: OK @@ -263,6 +283,8 @@ interactions: - '854' content-type: - application/json; charset=UTF-8 + x-elastic-product: + - Elasticsearch status: code: 200 message: OK @@ -287,6 +309,8 @@ interactions: - '21' content-type: - application/json; charset=UTF-8 + x-elastic-product: + - Elasticsearch status: code: 200 message: OK @@ -311,6 +335,8 @@ interactions: - '21' content-type: - application/json; charset=UTF-8 + x-elastic-product: + - Elasticsearch status: code: 200 message: OK @@ -335,6 +361,8 @@ interactions: - '96' content-type: - application/json; charset=UTF-8 + x-elastic-product: + - Elasticsearch status: code: 200 message: OK @@ -357,6 +385,8 @@ interactions: - '106' content-type: - application/json; charset=UTF-8 + x-elastic-product: + - Elasticsearch status: code: 200 message: OK diff --git a/connector_elasticsearch/tests/test_connector_elasticsearch.py b/connector_elasticsearch/tests/test_connector_elasticsearch.py index c60bb061..b73f5780 100644 --- a/connector_elasticsearch/tests/test_connector_elasticsearch.py +++ b/connector_elasticsearch/tests/test_connector_elasticsearch.py @@ -57,7 +57,7 @@ def test_index_adapter(self): self.assertGreaterEqual(len(self.cassette.requests), 1) request = self.cassette.requests[-1] - self.assertEqual(request.method, "POST") + self.assertEqual(request.method, "PUT") self.assertEqual(self.parse_path(request.uri), "/_bulk") body = request.body.decode("utf-8") lines = [line for line in filter(lambda line: line, body.split("\n"))] @@ -107,13 +107,13 @@ def test_index_adapter_delete(self): res.sort(key=lambda d: d["id"]) self.assertListEqual(res, [{"id": "foo2"}]) - @mute_logger("odoo.addons.connector_search_engine.models.se_binding") def test_index_adapter_delete_nonexisting_documents(self): """We try to delete records that do not exist. Because it does not matter, it is just ignored. No exception. """ self.adapter.delete(["donotexist", "donotexisteither"]) + @mute_logger("py.warnings") # mute GeneralAvailabilityWarning def test_index_adapter_reindex(self): data = [{"id": "foo"}, {"id": "foo2"}, {"id": "foo3"}] self.adapter.clear() diff --git a/connector_elasticsearch/tools/adapter.py b/connector_elasticsearch/tools/adapter.py index 5380b238..d69cba7a 100644 --- a/connector_elasticsearch/tools/adapter.py +++ b/connector_elasticsearch/tools/adapter.py @@ -18,6 +18,10 @@ import elasticsearch.helpers except ImportError: _logger.debug("Can not import elasticsearch") +try: + from elastic_transport import RequestsHttpNode +except ImportError: + _logger.debug("Can not import from elastic_transport") def _is_delete_nonexistent_documents(elastic_exception): @@ -37,7 +41,7 @@ def _index_name(self): @property def _es_connection_class(self): - return elasticsearch.RequestsHttpConnection + return RequestsHttpNode @property def _es_client(self): @@ -51,30 +55,28 @@ def _index_config(self): def _get_es_client(self): backend = self.backend_record + es_params = { + "hosts": [backend.es_server_host], + } + es_options = { + "request_timeout": max(backend.es_timeout, 1), + "retry_on_timeout": backend.es_retry_on_timeout, + "max_retries": max(0, backend.es_max_retries), + } if backend.auth_type == "api_key": api_key = ( (backend.api_key_id, backend.api_key) if backend.api_key_id and backend.api_key else None ) - return elasticsearch.Elasticsearch( - [backend.es_server_host], - connection_class=self._es_connection_class, - api_key=api_key, - timeout=max(backend.es_timeout, 1), - retry_on_timeout=backend.es_retry_on_timeout, - max_retries=max(0, backend.es_max_retries), - ) + es_params["node_class"] = self._es_connection_class + es_options["api_key"] = api_key if backend.auth_type == "http": auth = (backend.es_user, backend.es_password) - return elasticsearch.Elasticsearch( - [backend.es_server_host], - http_auth=auth, - use_ssl=backend.ssl, - timeout=max(backend.es_timeout, 1), - retry_on_timeout=backend.es_retry_on_timeout, - max_retries=max(0, backend.es_max_retries), - ) + es_params["http_auth"] = auth + client = elasticsearch.Elasticsearch(**es_params) + client.options(**es_options) + return client def test_connection(self): es = self._es_client @@ -133,7 +135,8 @@ def delete(self, binding_ids) -> None: def clear(self) -> None: es = self._es_client index_name = self._get_current_aliased_index_name() or self._index_name - res = es.indices.delete(index=index_name, ignore=[400, 404]) + es.options(ignore_status=[400, 404]) + res = es.indices.delete(index=index_name) self.settings() if not res["acknowledged"]: raise SystemError( @@ -156,7 +159,7 @@ def each(self) -> Iterator[dict[str, Any]]: def settings(self) -> None: es = self._es_client - if not es.indices.exists(self._index_name): + if not es.indices.exists(index=self._index_name): client = self._es_client # To allow rolling updates, we work with index aliases aliased_index_name = self._get_next_aliased_index_name() @@ -172,9 +175,9 @@ def settings(self) -> None: def _get_current_aliased_index_name(self) -> str: """Get the current aliased index name if any""" current_aliased_index_name = None - alias = self._es_client.indices.get_alias( - name=self._index_name, ignore=[400, 404] - ) + client = self._es_client + client.options(ignore_status=[400, 404]) + alias = client.indices.get_alias(name=self._index_name) if "error" not in alias: current_aliased_index_name = next(iter(alias)) # get the first key return current_aliased_index_name @@ -213,11 +216,11 @@ def reindex(self) -> None: # create new idx client.indices.create(index=next_aliased_index_name, body=self._index_config) task_def = client.reindex( - { + body={ "source": {"index": self._index_name}, "dest": {"index": next_aliased_index_name}, }, - request_timeout=9999999, + timeout="9999999", wait_for_completion=False, ) while True: @@ -245,11 +248,14 @@ def reindex(self) -> None: ] } ) - client.indices.delete(index=current_aliased_index_name, ignore=[400, 404]) + client.options(ignore_status=[400, 404]) + client.indices.delete(index=current_aliased_index_name) else: # This code will only be triggered the first time the reindex is # called on an index created before the use of index aliases. - client.indices.delete(index=self._index_name, ignore=[400, 404]) + client.options(ignore_status=[400, 404]) + client.indices.delete(index=self._index_name) + client.options(ignore_status=[]) client.indices.put_alias( index=next_aliased_index_name, name=self._index_name ) diff --git a/connector_elasticsearch/views/se_backend.xml b/connector_elasticsearch/views/se_backend.xml index eed73503..2fc11191 100644 --- a/connector_elasticsearch/views/se_backend.xml +++ b/connector_elasticsearch/views/se_backend.xml @@ -27,11 +27,6 @@ attrs="{'invisible': [('auth_type', '!=', 'http')]}" password="1" /> - =7.0.0,<=7.13.4 +elastic-transport>=8.15.1,<9.0.0 +elasticsearch>=8.0.0,<9.0.0 pydantic requests typing-extensions