Skip to content

elasticsearch9 cross-version imports incompatibility #3224

@bantucaravan

Description

@bantucaravan

Problem Description

I have a code base that reads/writes to both an elasticsearch 7 and elasticsearch 9 cluster. We are building a new process on the upgraded instance before migrating the existing processes.

We use elasticsearch base SDK as well as elasticsearch DSL for both versions. The elasticsearch9 package is provided for compatibilty in exactly these circumstances (see: https://www.elastic.co/docs/reference/elasticsearch/clients/python). However elasticsearch9.dsl imports internally from the elasticsearch module name directly, rather than from elasticsearch9. This is unlike the pattern in the elasticsearch7_dsl compatibility package which internally imports from elasticsearch7.

How to Replicate

python3.10 -m venv .venv
source .venv/bin/activate
pip install elasticsearch9 elasticsearch7 elasticsearch7-dsl
import elasticsearch9.dsl

raises..

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
File /Users/noahchasekmacfoy/Desktop/repos/es_sdk_version_mismatch_bug/example.py:1
----> 1 import elasticsearch9.dsl

File ~/Desktop/repos/es_sdk_version_mismatch_bug/.venv/lib/python3.10/site-packages/elasticsearch9/dsl/__init__.py:18
      1 #  Licensed to Elasticsearch B.V. under one or more contributor
      2 #  license agreements. See the NOTICE file distributed with
      3 #  this work for additional information regarding copyright
   (...)
     15 #  specific language governing permissions and limitations
     16 #  under the License.
---> 18 from . import async_connections, connections
     19 from .aggs import A, Agg
     20 from .analysis import analyzer, char_filter, normalizer, token_filter, tokenizer

File ~/Desktop/repos/es_sdk_version_mismatch_bug/.venv/lib/python3.10/site-packages/elasticsearch9/dsl/async_connections.py:20
      1 #  Licensed to Elasticsearch B.V. under one or more contributor
      2 #  license agreements. See the NOTICE file distributed with
      3 #  this work for additional information regarding copyright
   (...)
     15 #  specific language governing permissions and limitations
     16 #  under the License.
     18 from typing import Type
---> 20 from elasticsearch import AsyncElasticsearch
     22 from .connections import Connections
     25 class AsyncElasticsearchConnections(Connections[AsyncElasticsearch]):

ModuleNotFoundError: No module named 'elasticsearch'

Expected behavior

no error

Proposed Solution

follow the pattern from elasticsearch7_dsl and change the import to elasticsearch9

I don't know where stand alone repo for this distribution is or how it is created otherwise I would make a pull request myself. Please let me know if I can make a PR directly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions