diff --git a/.ci/Dockerfile.client b/.ci/Dockerfile.client index 09181986..1b3a937a 100644 --- a/.ci/Dockerfile.client +++ b/.ci/Dockerfile.client @@ -1,7 +1,7 @@ ARG PYTHON_VERSION=3.8 FROM python:${PYTHON_VERSION} -WORKDIR /code/elasticsearch-py +WORKDIR /code/opensearch-py COPY dev-requirements.txt . RUN python -m pip install \ -U --no-cache-dir \ diff --git a/.ci/functions/imports.sh b/.ci/functions/imports.sh index 6d4e0fa4..8b02c1e5 100755 --- a/.ci/functions/imports.sh +++ b/.ci/functions/imports.sh @@ -12,13 +12,16 @@ if [[ -z $es_node_name ]]; then export RUNSCRIPTS=${RUNSCRIPTS-} export DETACH=${DETACH-false} export CLEANUP=${CLEANUP-false} - export ELASTICSEARCH_URL_EXTENSION=${ELASTICSEARCH_URL_EXTENSION-http} + export OPENSEARCH_URL_EXTENSION=${OPENSEARCH_URL_EXTENSION-http} export es_node_name=instance - export elastic_password=changeme + export opensearch_image=opensearchproject/opensearch + if [[ "$CLUSTER" == "opendistro" ]]; then + export opensearch_image=amazon/opendistro-for-elasticsearch + fi - export elasticsearch_url=$ELASTICSEARCH_URL_EXTENSION://${es_node_name}:9200 - export external_elasticsearch_url=${elasticsearch_url/$es_node_name/localhost} + export opensearch_url=$OPENSEARCH_URL_EXTENSION://${opensearch_node_name}:9200 + export external_opensearch_url=${opensearch_url/$opensearch_node_name/localhost} export network_name=search-rest-test diff --git a/.ci/make.sh b/.ci/make.sh index c4463660..1e8985dd 100755 --- a/.ci/make.sh +++ b/.ci/make.sh @@ -2,7 +2,7 @@ # ------------------------------------------------------- # # -# Skeleton for common build entry script for all elastic +# Skeleton for common build entry script for all opensearch # clients. Needs to be adapted to individual client usage. # # Must be called: ./.ci/make.sh @@ -35,7 +35,7 @@ VERSION=$2 STACK_VERSION=$VERSION set -euo pipefail -product="elastic/elasticsearch-py" +product="opensearch-project/opensearch-py" output_folder=".ci/output" codegen_folder=".ci/output" OUTPUT_DIR="$repo/${output_folder}" @@ -129,15 +129,15 @@ if [[ "$CMD" == "assemble" ]]; then # Build dists into .ci/output docker run \ - --rm -v $repo/.ci/output:/code/elasticsearch-py/dist \ + --rm -v $repo/.ci/output:/code/opensearch-py/dist \ $product \ - /bin/bash -c "python /code/elasticsearch-py/utils/build-dists.py $VERSION" + /bin/bash -c "python /code/opensearch-py/utils/build-dists.py $VERSION" # Verify that there are dists in .ci/output if compgen -G ".ci/output/*" > /dev/null; then # Tarball everything up in .ci/output - cd $repo/.ci/output && tar -czvf elasticsearch-py-$VERSION.tar.gz * && cd - + cd $repo/.ci/output && tar -czvf opensearch-py-$VERSION.tar.gz * && cd - echo -e "\033[32;1mTARGET: successfully assembled client v$VERSION\033[0m" exit 0 diff --git a/.ci/run-elasticsearch.sh b/.ci/run-opensearch.sh similarity index 90% rename from .ci/run-elasticsearch.sh rename to .ci/run-opensearch.sh index f9c08fdb..9f897818 100755 --- a/.ci/run-elasticsearch.sh +++ b/.ci/run-opensearch.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash # -# Launch one or more Elasticsearch nodes via the Docker image, +# Launch one or more OpenSearch nodes via the Docker image, # to form a cluster suitable for running the REST API tests. # # Export the STACK_VERSION variable, eg. '8.0.0-SNAPSHOT'. @@ -8,7 +8,7 @@ # Export the NUMBER_OF_NODES variable to start more than 1 node # Version 1.4.0 -# - Initial version of the run-elasticsearch.sh script +# - Initial version of the run-opensearch.sh script # - Deleting the volume should not dependent on the container still running # - Fixed `ES_JAVA_OPTS` config # - Moved to STACK_VERSION and TEST_VERSION @@ -47,7 +47,7 @@ NUMBER_OF_NODES=${NUMBER_OF_NODES-1} http_port=9200 for (( i=0; i<$NUMBER_OF_NODES; i++, http_port++ )); do node_name=${es_node_name}$i - node_url=${external_elasticsearch_url/9200/${http_port}}$i + node_url=${external_opensearch_url/9200/${http_port}}$i if [[ "$i" == "0" ]]; then node_name=$es_node_name; fi environment+=($(cat <<-END --env node.name=$node_name @@ -56,7 +56,7 @@ END echo "$i: $http_port $node_url " volume_name=${node_name}-rest-test-data volumes+=($(cat <<-END - --volume $volume_name:/usr/share/elasticsearch/data${i} + --volume $volume_name:/usr/share/opensearch/data${i} END )) @@ -84,7 +84,7 @@ END --ulimit nofile=65536:65536 \ --ulimit memlock=-1:-1 \ --detach="$local_detach" \ - --health-cmd="curl -vvv -s --fail $elasticsearch_url/_cluster/health || exit 1" \ + --health-cmd="curl -vvv -s --fail $opensearch_url/_cluster/health || exit 1" \ --health-interval=2s \ --health-retries=20 \ --health-timeout=2s \ diff --git a/.ci/run-repository.sh b/.ci/run-repository.sh index feb4e4f6..7c89ec8f 100755 --- a/.ci/run-repository.sh +++ b/.ci/run-repository.sh @@ -1,43 +1,43 @@ #!/usr/bin/env bash # Called by entry point `run-test` use this script to add your repository specific test commands -# Once called Elasticsearch is up and running and the following parameters are available to this script +# Once called opensearch is up and running and the following parameters are available to this script -# ELASTICSEARCH_VERSION -- version e.g Major.Minor.Patch(-Prelease) -# ELASTICSEARCH_URL -- The url at which elasticsearch is reachable +# OPENSEARCH_VERSION -- version e.g Major.Minor.Patch(-Prelease) +# OPENSEARCH_URL -- The url at which opensearch is reachable # network_name -- The docker network name -# NODE_NAME -- The docker container name also used as Elasticsearch node name +# NODE_NAME -- The docker container name also used as opensearch node name # When run in CI the test-matrix is used to define additional variables # TEST_SUITE -- defaults to `oss` in `run-tests` set -e -echo -e "\033[34;1mINFO:\033[0m URL ${elasticsearch_url}\033[0m" -echo -e "\033[34;1mINFO:\033[0m VERSION ${ELASTICSEARCH_VERSION}\033[0m" +echo -e "\033[34;1mINFO:\033[0m URL ${opensearch_url}\033[0m" +echo -e "\033[34;1mINFO:\033[0m VERSION ${OPENSEARCH_VERSION}\033[0m" echo -e "\033[34;1mINFO:\033[0m TEST_SUITE ${TEST_SUITE}\033[0m" echo -e "\033[34;1mINFO:\033[0m PYTHON_VERSION ${PYTHON_VERSION}\033[0m" echo -e "\033[34;1mINFO:\033[0m PYTHON_CONNECTION_CLASS ${PYTHON_CONNECTION_CLASS}\033[0m" -echo -e "\033[1m>>>>> Build [elastic/elasticsearch-py container] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>\033[0m" +echo -e "\033[1m>>>>> Build [opensearch-project/opensearch-py container] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>\033[0m" docker build \ --file .ci/Dockerfile.client \ - --tag elastic/elasticsearch-py \ + --tag opensearch-project/opensearch-py \ --build-arg PYTHON_VERSION=${PYTHON_VERSION} \ . -echo -e "\033[1m>>>>> Run [elastic/elasticsearch-py container] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>\033[0m" +echo -e "\033[1m>>>>> Run [opensearch-project/opensearch-py container] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>\033[0m" mkdir -p junit docker run \ --network=${network_name} \ --env "STACK_VERSION=${STACK_VERSION}" \ - --env "ELASTICSEARCH_URL=${elasticsearch_url}" \ + --env "OPENSEARCH_URL=${opensearch_url}" \ --env "TEST_SUITE=${TEST_SUITE}" \ --env "PYTHON_CONNECTION_CLASS=${PYTHON_CONNECTION_CLASS}" \ --env "TEST_TYPE=server" \ - --name elasticsearch-py \ + --name opensearch-py \ --rm \ - elastic/elasticsearch-py \ + opensearch-project/opensearch-py \ python setup.py test diff --git a/.ci/run-tests b/.ci/run-tests index 7984d37d..eb49297a 100755 --- a/.ci/run-tests +++ b/.ci/run-tests @@ -2,21 +2,20 @@ # # Version 1.1 # - Moved to .ci folder and seperated out `run-repository.sh` -# - Add `$RUNSCRIPTS` env var for running Elasticsearch dependent products +# - Add `$RUNSCRIPTS` env var for running opensearch dependent products # Default environment variables export TEST_SUITE="${TEST_SUITE:=oss}" export PYTHON_VERSION="${PYTHON_VERSION:=3.9}" export PYTHON_CONNECTION_CLASS="${PYTHON_CONNECTION_CLASS:=Urllib3HttpConnection}" -export ELASTICSEARCH_URL_EXTENSION="${ELASTICSEARCH_URL_EXTENSION:=http}" +export OPENSEARCH_URL_EXTENSION="${OPENSEARCH_URL_EXTENSION:=http}" export CLUSTER="${1:=opensearch}" script_path=$(dirname $(realpath -s $0)) source $script_path/functions/imports.sh set -euo pipefail -echo -e "\033[1m>>>>> Start server container >>>>>>>>>>>>>>>>>>>>>>>>>>>>>\033[0m" -DETACH=true bash .ci/run-elasticsearch.sh +DETACH=true bash .ci/run-opensearch.sh if [[ -n "$RUNSCRIPTS" ]]; then for RUNSCRIPT in ${RUNSCRIPTS//,/ } ; do diff --git a/.coveragerc b/.coveragerc index 2f0477db..1b096851 100644 --- a/.coveragerc +++ b/.coveragerc @@ -5,5 +5,5 @@ omit = */lib_pypy/* */site-packages/* *.egg/* - test_elasticsearch/* - elasticsearch/connection/esthrift/* + test_opensearch/* + opensearch/connection/esthrift/* diff --git a/.gitignore b/.gitignore index f762a205..899d42e1 100644 --- a/.gitignore +++ b/.gitignore @@ -137,7 +137,7 @@ cython_debug/ # Pycharm project settings .idea -# elasticsearch files -test_elasticsearch/cover -test_elasticsearch/local.py +# opensearch files +test_opensearch/cover +test_opensearch/local.py .ci/output diff --git a/MANIFEST.in b/MANIFEST.in index ce967691..40d49135 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -5,8 +5,8 @@ include LICENSE include MANIFEST.in include README.md include setup.py -recursive-include elasticsearch* py.typed *.pyi +recursive-include opensearch* py.typed *.pyi -prune test_elasticsearch +prune test_opensearch recursive-exclude * __pycache__ recursive-exclude * *.py[co] diff --git a/Makefile b/Makefile index 0884e86a..c4cc2a01 100644 --- a/Makefile +++ b/Makefile @@ -5,14 +5,14 @@ build: PYTHON_VERSION=${PYTHON_VERSION} docker-compose build client pull: - ELASTICSEARCH_VERSION=${ELASTICSEARCH_VERSION} PYTHON_VERSION=${PYTHON_VERSION} docker-compose pull + OPENSEARCH_VERSION=${OPENSEARCH_VERSION} PYTHON_VERSION=${PYTHON_VERSION} docker-compose pull push: # requires authentication. PYTHON_VERSION=${PYTHON_VERSION} docker-compose push client run_tests: - ELASTICSEARCH_VERSION=${ELASTICSEARCH_VERSION} PYTHON_VERSION=${PYTHON_VERSION} docker-compose -p "${ELASTIC_VERSION}-${PYTHON_VERSION}" run client python setup.py test + OPENSEARCH_VERSION=${OPENSEARCH_VERSION} PYTHON_VERSION=${PYTHON_VERSION} docker-compose -p "${OPEN_VERSION}-${PYTHON_VERSION}" run client python setup.py test -start_elasticsearch: - ELASTICSEARCH_VERSION=${ELASTICSEARCH_VERSION} docker-compose up -d elasticsearch +start_opensearch: + OPENSEARCH_VERSION=${OPENSEARCH_VERSION} docker-compose up -d opensearch diff --git a/noxfile.py b/noxfile.py index 8801499f..1f08f3b3 100644 --- a/noxfile.py +++ b/noxfile.py @@ -29,8 +29,8 @@ import nox SOURCE_FILES = ( "setup.py", "noxfile.py", - "elasticsearch/", - "test_elasticsearch/", + "opensearch/", + "test_opensearch/", "utils/", ) @@ -68,15 +68,15 @@ def lint(session): # Run mypy on the package and then the type examples separately for # the two different mypy use-cases, ourselves and our users. - session.run("mypy", "--strict", "elasticsearch/") - session.run("mypy", "--strict", "test_elasticsearch/test_types/sync_types.py") - session.run("mypy", "--strict", "test_elasticsearch/test_types/async_types.py") + session.run("mypy", "--strict", "opensearch/") + session.run("mypy", "--strict", "test_opensearch/test_types/sync_types.py") + session.run("mypy", "--strict", "test_opensearch/test_types/async_types.py") # Make sure we don't require aiohttp to be installed for users to # receive type hint information from mypy. session.run("python", "-m", "pip", "uninstall", "--yes", "aiohttp") - session.run("mypy", "--strict", "elasticsearch/") - session.run("mypy", "--strict", "test_elasticsearch/test_types/sync_types.py") + session.run("mypy", "--strict", "opensearch/") + session.run("mypy", "--strict", "test_opensearch/test_types/sync_types.py") @nox.session() diff --git a/elasticsearch/__init__.py b/opensearch/__init__.py similarity index 86% rename from elasticsearch/__init__.py rename to opensearch/__init__.py index 5524e514..0fc047ac 100644 --- a/elasticsearch/__init__.py +++ b/opensearch/__init__.py @@ -39,10 +39,10 @@ _major, _minor, _patch = [ ] VERSION = __version__ = (_major, _minor, _patch) -logger = logging.getLogger("elasticsearch") +logger = logging.getLogger("opensearch") logger.addHandler(logging.NullHandler()) -from .client import Elasticsearch +from .client import OpenSearch from .connection import Connection, RequestsHttpConnection, Urllib3HttpConnection from .connection_pool import ConnectionPool, ConnectionSelector, RoundRobinSelector from .exceptions import ( @@ -51,11 +51,11 @@ from .exceptions import ( ConflictError, ConnectionError, ConnectionTimeout, - ElasticsearchDeprecationWarning, - ElasticsearchException, - ElasticsearchWarning, ImproperlyConfigured, NotFoundError, + OpenSearchDeprecationWarning, + OpenSearchException, + OpenSearchWarning, RequestError, SerializationError, SSLError, @@ -66,10 +66,10 @@ from .transport import Transport # Only raise one warning per deprecation message so as not # to spam up the user if the same action is done multiple times. -warnings.simplefilter("default", category=ElasticsearchDeprecationWarning, append=True) +warnings.simplefilter("default", category=OpenSearchDeprecationWarning, append=True) __all__ = [ - "Elasticsearch", + "OpenSearch", "Transport", "ConnectionPool", "ConnectionSelector", @@ -79,7 +79,7 @@ __all__ = [ "RequestsHttpConnection", "Urllib3HttpConnection", "ImproperlyConfigured", - "ElasticsearchException", + "OpenSearchException", "SerializationError", "TransportError", "NotFoundError", @@ -90,8 +90,8 @@ __all__ = [ "ConnectionTimeout", "AuthenticationException", "AuthorizationException", - "ElasticsearchWarning", - "ElasticsearchDeprecationWarning", + "OpenSearchWarning", + "OpenSearchDeprecationWarning", ] try: @@ -99,7 +99,7 @@ try: if sys.version_info < (3, 6): raise ImportError - from ._async.client import AsyncElasticsearch + from ._async.client import AsyncOpenSearch from ._async.http_aiohttp import AIOHttpConnection, AsyncConnection from ._async.transport import AsyncTransport @@ -107,7 +107,7 @@ try: "AIOHttpConnection", "AsyncConnection", "AsyncTransport", - "AsyncElasticsearch", + "AsyncOpenSearch", ] except (ImportError, SyntaxError): pass diff --git a/elasticsearch/__init__.pyi b/opensearch/__init__.pyi similarity index 89% rename from elasticsearch/__init__.pyi rename to opensearch/__init__.pyi index b820e8f9..e235ae2e 100644 --- a/elasticsearch/__init__.pyi +++ b/opensearch/__init__.pyi @@ -27,7 +27,7 @@ import sys from typing import Tuple -from .client import Elasticsearch as Elasticsearch +from .client import OpenSearch as OpenSearch from .connection import Connection as Connection from .connection import RequestsHttpConnection as RequestsHttpConnection from .connection import Urllib3HttpConnection as Urllib3HttpConnection @@ -39,12 +39,10 @@ from .exceptions import AuthorizationException as AuthorizationException from .exceptions import ConflictError as ConflictError from .exceptions import ConnectionError as ConnectionError from .exceptions import ConnectionTimeout as ConnectionTimeout -from .exceptions import ( - ElasticsearchDeprecationWarning as ElasticsearchDeprecationWarning, -) -from .exceptions import ElasticsearchException as ElasticsearchException from .exceptions import ImproperlyConfigured as ImproperlyConfigured from .exceptions import NotFoundError as NotFoundError +from .exceptions import OpenSearchDeprecationWarning as OpenSearchDeprecationWarning +from .exceptions import OpenSearchException as OpenSearchException from .exceptions import RequestError as RequestError from .exceptions import SerializationError as SerializationError from .exceptions import SSLError as SSLError @@ -56,7 +54,7 @@ try: if sys.version_info < (3, 6): raise ImportError - from ._async.client import AsyncElasticsearch as AsyncElasticsearch + from ._async.client import AsyncOpenSearch as AsyncOpenSearch from ._async.http_aiohttp import AIOHttpConnection as AIOHttpConnection from ._async.transport import AsyncTransport as AsyncTransport except (ImportError, SyntaxError): diff --git a/elasticsearch/_async/__init__.py b/opensearch/_async/__init__.py similarity index 100% rename from elasticsearch/_async/__init__.py rename to opensearch/_async/__init__.py diff --git a/elasticsearch/_async/_extra_imports.py b/opensearch/_async/_extra_imports.py similarity index 100% rename from elasticsearch/_async/_extra_imports.py rename to opensearch/_async/_extra_imports.py diff --git a/elasticsearch/_async/client/__init__.py b/opensearch/_async/client/__init__.py similarity index 98% rename from elasticsearch/_async/client/__init__.py rename to opensearch/_async/client/__init__.py index b974aba2..1f323726 100644 --- a/elasticsearch/_async/client/__init__.py +++ b/opensearch/_async/client/__init__.py @@ -42,23 +42,23 @@ from .snapshot import SnapshotClient from .tasks import TasksClient from .utils import SKIP_IN_PATH, _bulk_body, _make_path, _normalize_hosts, query_params -logger = logging.getLogger("elasticsearch") +logger = logging.getLogger("opensearch") -class AsyncElasticsearch(object): +class AsyncOpenSearch(object): """ - Elasticsearch low-level client. Provides a straightforward mapping from + OpenSearch low-level client. Provides a straightforward mapping from Python to ES REST endpoints. The instance has attributes ``cat``, ``cluster``, ``indices``, ``ingest``, ``nodes``, ``snapshot`` and ``tasks`` that provide access to instances of - :class:`~elasticsearch.client.CatClient`, - :class:`~elasticsearch.client.ClusterClient`, - :class:`~elasticsearch.client.IndicesClient`, - :class:`~elasticsearch.client.IngestClient`, - :class:`~elasticsearch.client.NodesClient`, - :class:`~elasticsearch.client.SnapshotClient` and - :class:`~elasticsearch.client.TasksClient` respectively. This is the + :class:`~opensearch.client.CatClient`, + :class:`~opensearch.client.ClusterClient`, + :class:`~opensearch.client.IndicesClient`, + :class:`~opensearch.client.IngestClient`, + :class:`~opensearch.client.NodesClient`, + :class:`~opensearch.client.SnapshotClient` and + :class:`~opensearch.client.TasksClient` respectively. This is the preferred (and only supported) way to get access to those classes and their methods. @@ -66,15 +66,15 @@ class AsyncElasticsearch(object): the ``connection_class`` parameter:: # create connection to localhost using the ThriftConnection - es = Elasticsearch(connection_class=ThriftConnection) + es = OpenSearch(connection_class=ThriftConnection) If you want to turn on :ref:`sniffing` you have several options (described - in :class:`~elasticsearch.Transport`):: + in :class:`~opensearch.Transport`):: # create connection that will automatically inspect the cluster to get # the list of active nodes. Start with nodes running on 'esnode1' and # 'esnode2' - es = Elasticsearch( + es = OpenSearch( ['esnode1', 'esnode2'], # sniff before doing anything sniff_on_start=True, @@ -89,16 +89,16 @@ class AsyncElasticsearch(object): # connect to localhost directly and another node using SSL on port 443 # and an url_prefix. Note that ``port`` needs to be an int. - es = Elasticsearch([ + es = OpenSearch([ {'host': 'localhost'}, {'host': 'othernode', 'port': 443, 'url_prefix': 'es', 'use_ssl': True}, ]) If using SSL, there are several parameters that control how we deal with - certificates (see :class:`~elasticsearch.Urllib3HttpConnection` for + certificates (see :class:`~opensearch.Urllib3HttpConnection` for detailed description of the options):: - es = Elasticsearch( + es = OpenSearch( ['localhost:443', 'other_host:443'], # turn on SSL use_ssl=True, @@ -109,10 +109,10 @@ class AsyncElasticsearch(object): ) If using SSL, but don't verify the certs, a warning message is showed - optionally (see :class:`~elasticsearch.Urllib3HttpConnection` for + optionally (see :class:`~opensearch.Urllib3HttpConnection` for detailed description of the options):: - es = Elasticsearch( + es = OpenSearch( ['localhost:443', 'other_host:443'], # turn on SSL use_ssl=True, @@ -123,10 +123,10 @@ class AsyncElasticsearch(object): ) SSL client authentication is supported - (see :class:`~elasticsearch.Urllib3HttpConnection` for + (see :class:`~opensearch.Urllib3HttpConnection` for detailed description of the options):: - es = Elasticsearch( + es = OpenSearch( ['localhost:443', 'other_host:443'], # turn on SSL use_ssl=True, @@ -143,7 +143,7 @@ class AsyncElasticsearch(object): Alternatively you can use RFC-1738 formatted URLs, as long as they are not in conflict with other options:: - es = Elasticsearch( + es = OpenSearch( [ 'http://user:secret@localhost:9200/', 'https://user:secret@other_host:443/production' @@ -152,11 +152,11 @@ class AsyncElasticsearch(object): ) By default, `JSONSerializer - `_ + `_ is used to encode all outgoing requests. However, you can implement your own custom serializer:: - from elasticsearch.serializer import JSONSerializer + from opensearch.serializer import JSONSerializer class SetEncoder(JSONSerializer): def default(self, obj): @@ -166,7 +166,7 @@ class AsyncElasticsearch(object): return 'CustomSomethingRepresentation' return JSONSerializer.default(self, obj) - es = Elasticsearch(serializer=SetEncoder()) + es = OpenSearch(serializer=SetEncoder()) """ @@ -174,16 +174,16 @@ class AsyncElasticsearch(object): """ :arg hosts: list of nodes, or a single node, we should connect to. Node should be a dictionary ({"host": "localhost", "port": 9200}), - the entire dictionary will be passed to the :class:`~elasticsearch.Connection` + the entire dictionary will be passed to the :class:`~opensearch.Connection` class as kwargs, or a string in the format of ``host[:port]`` which will be translated to a dictionary automatically. If no value is given the - :class:`~elasticsearch.Connection` class defaults will be used. + :class:`~opensearch.Connection` class defaults will be used. - :arg transport_class: :class:`~elasticsearch.Transport` subclass to use. + :arg transport_class: :class:`~opensearch.Transport` subclass to use. :arg kwargs: any additional arguments will be passed on to the - :class:`~elasticsearch.Transport` class and, subsequently, to the - :class:`~elasticsearch.Connection` instances. + :class:`~opensearch.Transport` class and, subsequently, to the + :class:`~opensearch.Connection` instances. """ self.transport = transport_class(_normalize_hosts(hosts), **kwargs) @@ -210,7 +210,7 @@ class AsyncElasticsearch(object): return "<{cls}({cons})>".format(cls=self.__class__.__name__, cons=cons) except Exception: # probably operating on custom transport and connection_pool, ignore - return super(AsyncElasticsearch, self).__repr__() + return super(AsyncOpenSearch, self).__repr__() async def __aenter__(self): if hasattr(self.transport, "_async_call"): diff --git a/elasticsearch/_async/client/__init__.pyi b/opensearch/_async/client/__init__.pyi similarity index 99% rename from elasticsearch/_async/client/__init__.pyi rename to opensearch/_async/client/__init__.pyi index 426b5400..81fbd6a6 100644 --- a/elasticsearch/_async/client/__init__.pyi +++ b/opensearch/_async/client/__init__.pyi @@ -44,7 +44,7 @@ from .tasks import TasksClient logger: logging.Logger -class AsyncElasticsearch(object): +class AsyncOpenSearch(object): transport: AsyncTransport cat: CatClient @@ -63,7 +63,7 @@ class AsyncElasticsearch(object): **kwargs: Any, ) -> None: ... def __repr__(self) -> str: ... - async def __aenter__(self) -> "AsyncElasticsearch": ... + async def __aenter__(self) -> "AsyncOpenSearch": ... async def __aexit__(self, *_: Any) -> None: ... async def close(self) -> None: ... # AUTO-GENERATED-API-DEFINITIONS # diff --git a/elasticsearch/_async/client/cat.py b/opensearch/_async/client/cat.py similarity index 100% rename from elasticsearch/_async/client/cat.py rename to opensearch/_async/client/cat.py diff --git a/elasticsearch/_async/client/cat.pyi b/opensearch/_async/client/cat.pyi similarity index 100% rename from elasticsearch/_async/client/cat.pyi rename to opensearch/_async/client/cat.pyi diff --git a/elasticsearch/_async/client/cluster.py b/opensearch/_async/client/cluster.py similarity index 100% rename from elasticsearch/_async/client/cluster.py rename to opensearch/_async/client/cluster.py diff --git a/elasticsearch/_async/client/cluster.pyi b/opensearch/_async/client/cluster.pyi similarity index 100% rename from elasticsearch/_async/client/cluster.pyi rename to opensearch/_async/client/cluster.pyi diff --git a/elasticsearch/_async/client/dangling_indices.py b/opensearch/_async/client/dangling_indices.py similarity index 100% rename from elasticsearch/_async/client/dangling_indices.py rename to opensearch/_async/client/dangling_indices.py diff --git a/elasticsearch/_async/client/dangling_indices.pyi b/opensearch/_async/client/dangling_indices.pyi similarity index 100% rename from elasticsearch/_async/client/dangling_indices.pyi rename to opensearch/_async/client/dangling_indices.pyi diff --git a/elasticsearch/_async/client/features.py b/opensearch/_async/client/features.py similarity index 100% rename from elasticsearch/_async/client/features.py rename to opensearch/_async/client/features.py diff --git a/elasticsearch/_async/client/features.pyi b/opensearch/_async/client/features.pyi similarity index 100% rename from elasticsearch/_async/client/features.pyi rename to opensearch/_async/client/features.pyi diff --git a/elasticsearch/_async/client/indices.py b/opensearch/_async/client/indices.py similarity index 100% rename from elasticsearch/_async/client/indices.py rename to opensearch/_async/client/indices.py diff --git a/elasticsearch/_async/client/indices.pyi b/opensearch/_async/client/indices.pyi similarity index 100% rename from elasticsearch/_async/client/indices.pyi rename to opensearch/_async/client/indices.pyi diff --git a/elasticsearch/_async/client/ingest.py b/opensearch/_async/client/ingest.py similarity index 100% rename from elasticsearch/_async/client/ingest.py rename to opensearch/_async/client/ingest.py diff --git a/elasticsearch/_async/client/ingest.pyi b/opensearch/_async/client/ingest.pyi similarity index 100% rename from elasticsearch/_async/client/ingest.pyi rename to opensearch/_async/client/ingest.pyi diff --git a/elasticsearch/_async/client/nodes.py b/opensearch/_async/client/nodes.py similarity index 99% rename from elasticsearch/_async/client/nodes.py rename to opensearch/_async/client/nodes.py index 55317e0f..9533aa32 100644 --- a/elasticsearch/_async/client/nodes.py +++ b/opensearch/_async/client/nodes.py @@ -37,7 +37,7 @@ class NodesClient(NamespacedClient): :arg body: An object containing the password for the - elasticsearch keystore + opensearch keystore :arg node_id: A comma-separated list of node IDs to span the reload/reinit call. Should stay empty because reloading usually involves all cluster nodes. diff --git a/elasticsearch/_async/client/nodes.pyi b/opensearch/_async/client/nodes.pyi similarity index 100% rename from elasticsearch/_async/client/nodes.pyi rename to opensearch/_async/client/nodes.pyi diff --git a/elasticsearch/_async/client/remote.py b/opensearch/_async/client/remote.py similarity index 100% rename from elasticsearch/_async/client/remote.py rename to opensearch/_async/client/remote.py diff --git a/elasticsearch/_async/client/remote.pyi b/opensearch/_async/client/remote.pyi similarity index 100% rename from elasticsearch/_async/client/remote.pyi rename to opensearch/_async/client/remote.pyi diff --git a/elasticsearch/_async/client/snapshot.py b/opensearch/_async/client/snapshot.py similarity index 100% rename from elasticsearch/_async/client/snapshot.py rename to opensearch/_async/client/snapshot.py diff --git a/elasticsearch/_async/client/snapshot.pyi b/opensearch/_async/client/snapshot.pyi similarity index 100% rename from elasticsearch/_async/client/snapshot.pyi rename to opensearch/_async/client/snapshot.pyi diff --git a/elasticsearch/_async/client/tasks.py b/opensearch/_async/client/tasks.py similarity index 100% rename from elasticsearch/_async/client/tasks.py rename to opensearch/_async/client/tasks.py diff --git a/elasticsearch/_async/client/tasks.pyi b/opensearch/_async/client/tasks.pyi similarity index 100% rename from elasticsearch/_async/client/tasks.pyi rename to opensearch/_async/client/tasks.pyi diff --git a/elasticsearch/_async/client/utils.py b/opensearch/_async/client/utils.py similarity index 100% rename from elasticsearch/_async/client/utils.py rename to opensearch/_async/client/utils.py diff --git a/elasticsearch/_async/client/utils.pyi b/opensearch/_async/client/utils.pyi similarity index 91% rename from elasticsearch/_async/client/utils.pyi rename to opensearch/_async/client/utils.pyi index 20596583..bf88f587 100644 --- a/elasticsearch/_async/client/utils.pyi +++ b/opensearch/_async/client/utils.pyi @@ -30,11 +30,11 @@ from ...client.utils import _escape as _escape from ...client.utils import _make_path as _make_path # noqa from ...client.utils import _normalize_hosts as _normalize_hosts from ...client.utils import query_params as query_params -from ..client import AsyncElasticsearch +from ..client import AsyncOpenSearch from ..transport import AsyncTransport class NamespacedClient: - client: AsyncElasticsearch - def __init__(self, client: AsyncElasticsearch) -> None: ... + client: AsyncOpenSearch + def __init__(self, client: AsyncOpenSearch) -> None: ... @property def transport(self) -> AsyncTransport: ... diff --git a/elasticsearch/_async/compat.py b/opensearch/_async/compat.py similarity index 100% rename from elasticsearch/_async/compat.py rename to opensearch/_async/compat.py diff --git a/elasticsearch/_async/compat.pyi b/opensearch/_async/compat.pyi similarity index 100% rename from elasticsearch/_async/compat.pyi rename to opensearch/_async/compat.pyi diff --git a/elasticsearch/_async/helpers.py b/opensearch/_async/helpers.py similarity index 90% rename from elasticsearch/_async/helpers.py rename to opensearch/_async/helpers.py index 22e30070..3bd245fe 100644 --- a/elasticsearch/_async/helpers.py +++ b/opensearch/_async/helpers.py @@ -24,8 +24,8 @@ # specific language governing permissions and limitations # under the License. -# Licensed to Elasticsearch B.V under one or more agreements. -# Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +# Licensed to Elasticsearch B.V.under one or more agreements. +# Elasticsearch B.V.licenses this file to you under the Apache 2.0 License. # See the LICENSE file in the project root for more information import asyncio @@ -40,9 +40,9 @@ from ..helpers.actions import ( expand_action, ) from ..helpers.errors import ScanError -from .client import AsyncElasticsearch # noqa +from .client import AsyncOpenSearch # noqa -logger = logging.getLogger("elasticsearch.helpers") +logger = logging.getLogger("opensearch.helpers") async def _chunk_actions(actions, chunk_size, max_chunk_bytes, serializer): @@ -73,7 +73,7 @@ async def _process_bulk_chunk( **kwargs ): """ - Send a bulk request to elasticsearch and process the output. + Send a bulk request to opensearch and process the output. """ if not isinstance(ignore_status, (list, tuple)): ignore_status = (ignore_status,) @@ -146,7 +146,7 @@ async def async_streaming_bulk( """ Streaming bulk consumes actions from the iterable passed in and yields results per action. For non-streaming usecases use - :func:`~elasticsearch.helpers.async_bulk` which is a wrapper around streaming + :func:`~opensearch.helpers.async_bulk` which is a wrapper around streaming bulk that returns summary information about the bulk operation once the entire input is consumed and sent. @@ -156,7 +156,7 @@ async def async_streaming_bulk( every subsequent rejection for the same chunk, for double the time every time up to ``max_backoff`` seconds. - :arg client: instance of :class:`~elasticsearch.AsyncElasticsearch` to use + :arg client: instance of :class:`~opensearch.AsyncOpenSearch` to use :arg actions: iterable or async iterable containing the actions to be executed :arg chunk_size: number of docs in one chunk sent to es (default: 500) :arg max_chunk_bytes: the maximum size of the request in bytes (default: 100MB) @@ -242,9 +242,9 @@ async def async_bulk( client, actions, stats_only=False, ignore_status=(), *args, **kwargs ): """ - Helper for the :meth:`~elasticsearch.AsyncElasticsearch.bulk` api that provides + Helper for the :meth:`~opensearch.AsyncOpenSearch.bulk` api that provides a more human friendly interface - it consumes an iterator of actions and - sends them to elasticsearch in chunks. It returns a tuple with summary + sends them to opensearch in chunks. It returns a tuple with summary information - number of successfully executed actions and either list of errors or number of errors if ``stats_only`` is set to ``True``. Note that by default we raise a ``BulkIndexError`` when we encounter an error so @@ -254,19 +254,19 @@ async def async_bulk( When errors are being collected original document data is included in the error dictionary which can lead to an extra high memory usage. If you need to process a lot of data and want to ignore/collect errors please consider - using the :func:`~elasticsearch.helpers.async_streaming_bulk` helper which will + using the :func:`~opensearch.helpers.async_streaming_bulk` helper which will just return the errors and not store them in memory. - :arg client: instance of :class:`~elasticsearch.AsyncElasticsearch` to use + :arg client: instance of :class:`~opensearch.AsyncOpenSearch` to use :arg actions: iterator containing the actions :arg stats_only: if `True` only report number of successful/failed operations instead of just number of successful and a list of error responses :arg ignore_status: list of HTTP status code that you want to ignore Any additional keyword arguments will be passed to - :func:`~elasticsearch.helpers.async_streaming_bulk` which is used to execute - the operation, see :func:`~elasticsearch.helpers.async_streaming_bulk` for more + :func:`~opensearch.helpers.async_streaming_bulk` which is used to execute + the operation, see :func:`~opensearch.helpers.async_streaming_bulk` for more accepted parameters. """ success, failed = 0, 0 @@ -304,7 +304,7 @@ async def async_scan( ): """ Simple abstraction on top of the - :meth:`~elasticsearch.AsyncElasticsearch.scroll` api - a simple iterator that + :meth:`~opensearch.AsyncOpenSearch.scroll` api - a simple iterator that yields all hits as returned by underlining scroll requests. By default scan does not return results in any pre-determined order. To @@ -313,8 +313,8 @@ async def async_scan( may be an expensive operation and will negate the performance benefits of using ``scan``. - :arg client: instance of :class:`~elasticsearch.AsyncElasticsearch` to use - :arg query: body for the :meth:`~elasticsearch.AsyncElasticsearch.search` api + :arg client: instance of :class:`~opensearch.AsyncOpenSearch` to use + :arg query: body for the :meth:`~opensearch.AsyncOpenSearch.search` api :arg scroll: Specify how long a consistent view of the index should be maintained for scrolled search :arg raise_on_error: raises an exception (``ScanError``) if an error is @@ -329,10 +329,10 @@ async def async_scan( scroll API at the end of the method on completion or error, defaults to true. :arg scroll_kwargs: additional kwargs to be passed to - :meth:`~elasticsearch.AsyncElasticsearch.scroll` + :meth:`~opensearch.AsyncOpenSearch.scroll` Any additional keyword arguments will be passed to the initial - :meth:`~elasticsearch.AsyncElasticsearch.search` call:: + :meth:`~opensearch.AsyncOpenSearch.search` call:: async_scan(es, query={"query": {"match": {"title": "python"}}}, @@ -428,8 +428,8 @@ async def async_reindex( to another, potentially (if `target_client` is specified) on a different cluster. If you don't specify the query you will reindex all the documents. - Since ``2.3`` a :meth:`~elasticsearch.AsyncElasticsearch.reindex` api is - available as part of elasticsearch itself. It is recommended to use the api + Since ``2.3`` a :meth:`~opensearch.AsyncOpenSearch.reindex` api is + available as part of opensearch itself. It is recommended to use the api instead of this helper wherever possible. The helper is here mostly for backwards compatibility and for situations where more flexibility is needed. @@ -438,20 +438,20 @@ async def async_reindex( This helper doesn't transfer mappings, just the data. - :arg client: instance of :class:`~elasticsearch.AsyncElasticsearch` to use (for + :arg client: instance of :class:`~opensearch.AsyncOpenSearch` to use (for read if `target_client` is specified as well) :arg source_index: index (or list of indices) to read documents from :arg target_index: name of the index in the target cluster to populate - :arg query: body for the :meth:`~elasticsearch.AsyncElasticsearch.search` api + :arg query: body for the :meth:`~opensearch.AsyncOpenSearch.search` api :arg target_client: optional, is specified will be used for writing (thus enabling reindex between clusters) :arg chunk_size: number of docs in one chunk sent to es (default: 500) :arg scroll: Specify how long a consistent view of the index should be maintained for scrolled search :arg scan_kwargs: additional kwargs to be passed to - :func:`~elasticsearch.helpers.async_scan` + :func:`~opensearch.helpers.async_scan` :arg bulk_kwargs: additional kwargs to be passed to - :func:`~elasticsearch.helpers.async_bulk` + :func:`~opensearch.helpers.async_bulk` """ target_client = client if target_client is None else target_client docs = async_scan( diff --git a/elasticsearch/_async/helpers.pyi b/opensearch/_async/helpers.pyi similarity index 93% rename from elasticsearch/_async/helpers.pyi rename to opensearch/_async/helpers.pyi index 8c8a7d44..366ad172 100644 --- a/elasticsearch/_async/helpers.pyi +++ b/opensearch/_async/helpers.pyi @@ -42,7 +42,7 @@ from typing import ( ) from ..serializer import Serializer -from .client import AsyncElasticsearch +from .client import AsyncOpenSearch logger: logging.Logger @@ -52,7 +52,7 @@ def _chunk_actions( actions: Any, chunk_size: int, max_chunk_bytes: int, serializer: Serializer ) -> AsyncGenerator[Any, None]: ... def _process_bulk_chunk( - client: AsyncElasticsearch, + client: AsyncOpenSearch, bulk_actions: Any, bulk_data: Any, raise_on_exception: bool = ..., @@ -66,7 +66,7 @@ def azip( *iterables: Union[Iterable[T], AsyncIterable[T]] ) -> AsyncGenerator[Tuple[T, ...], None]: ... def async_streaming_bulk( - client: AsyncElasticsearch, + client: AsyncOpenSearch, actions: Union[Iterable[Any], AsyncIterable[Any]], chunk_size: int = ..., max_chunk_bytes: int = ..., @@ -82,7 +82,7 @@ def async_streaming_bulk( **kwargs: Any ) -> AsyncGenerator[Tuple[bool, Any], None]: ... async def async_bulk( - client: AsyncElasticsearch, + client: AsyncOpenSearch, actions: Union[Iterable[Any], AsyncIterable[Any]], stats_only: bool = ..., ignore_status: Optional[Union[int, Collection[int]]] = ..., @@ -90,7 +90,7 @@ async def async_bulk( **kwargs: Any ) -> Tuple[int, Union[int, List[Any]]]: ... def async_scan( - client: AsyncElasticsearch, + client: AsyncOpenSearch, query: Optional[Any] = ..., scroll: str = ..., raise_on_error: bool = ..., @@ -102,11 +102,11 @@ def async_scan( **kwargs: Any ) -> AsyncGenerator[int, None]: ... async def async_reindex( - client: AsyncElasticsearch, + client: AsyncOpenSearch, source_index: Union[str, Collection[str]], target_index: str, query: Any = ..., - target_client: Optional[AsyncElasticsearch] = ..., + target_client: Optional[AsyncOpenSearch] = ..., chunk_size: int = ..., scroll: str = ..., scan_kwargs: Optional[Mapping[str, Any]] = ..., diff --git a/elasticsearch/_async/http_aiohttp.py b/opensearch/_async/http_aiohttp.py similarity index 98% rename from elasticsearch/_async/http_aiohttp.py rename to opensearch/_async/http_aiohttp.py index 7c301cfb..c30884b0 100644 --- a/elasticsearch/_async/http_aiohttp.py +++ b/opensearch/_async/http_aiohttp.py @@ -106,11 +106,11 @@ class AIOHttpConnection(AsyncConnection): **kwargs, ): """ - Default connection class for ``AsyncElasticsearch`` using the `aiohttp` library and the http protocol. + Default connection class for ``AsyncOpenSearch`` using the `aiohttp` library and the http protocol. :arg host: hostname of the node (default: localhost) :arg port: port to use (integer, default: 9200) - :arg url_prefix: optional url prefix for elasticsearch + :arg url_prefix: optional url prefix for opensearch :arg timeout: default timeout in seconds (float, default: 10) :arg http_auth: optional http auth information as either ':' separated string or a tuple diff --git a/elasticsearch/_async/http_aiohttp.pyi b/opensearch/_async/http_aiohttp.pyi similarity index 100% rename from elasticsearch/_async/http_aiohttp.pyi rename to opensearch/_async/http_aiohttp.pyi diff --git a/elasticsearch/_async/transport.py b/opensearch/_async/transport.py similarity index 96% rename from elasticsearch/_async/transport.py rename to opensearch/_async/transport.py index 0aad3dc3..e14eb921 100644 --- a/elasticsearch/_async/transport.py +++ b/opensearch/_async/transport.py @@ -39,7 +39,7 @@ from ..transport import Transport from .compat import get_running_loop from .http_aiohttp import AIOHttpConnection -logger = logging.getLogger("elasticsearch") +logger = logging.getLogger("opensearch") class AsyncTransport(Transport): @@ -56,8 +56,8 @@ class AsyncTransport(Transport): """ :arg hosts: list of dictionaries, each containing keyword arguments to create a `connection_class` instance - :arg connection_class: subclass of :class:`~elasticsearch.Connection` to use - :arg connection_pool_class: subclass of :class:`~elasticsearch.ConnectionPool` to use + :arg connection_class: subclass of :class:`~opensearch.Connection` to use + :arg connection_pool_class: subclass of :class:`~opensearch.ConnectionPool` to use :arg host_info_callback: callback responsible for taking the node information from `/_cluster/nodes`, along with already extracted information, and producing a list of arguments (same as `hosts` parameter) @@ -114,7 +114,7 @@ class AsyncTransport(Transport): that was deferred within __init__() should be done here now. This method will only be called once per AsyncTransport instance - and is called from one of AsyncElasticsearch.__aenter__(), + and is called from one of AsyncOpenSearch.__aenter__(), AsyncTransport.perform_request() or AsyncTransport.get_connection() """ # Detect the async loop we're running in and set it @@ -300,7 +300,7 @@ class AsyncTransport(Transport): Mark a connection as dead (failed) in the connection pool. If sniffing on failure is enabled this will initiate the sniffing process. - :arg connection: instance of :class:`~elasticsearch.Connection` that failed + :arg connection: instance of :class:`~opensearch.Connection` that failed """ self.connection_pool.mark_dead(connection) if self.sniff_on_connection_fail: @@ -324,9 +324,9 @@ class AsyncTransport(Transport): :arg method: HTTP method to use :arg url: absolute url (without host) to target :arg headers: dictionary of headers, will be handed over to the - underlying :class:`~elasticsearch.Connection` class + underlying :class:`~opensearch.Connection` class :arg params: dictionary of query parameters, will be handed over to the - underlying :class:`~elasticsearch.Connection` class for serialization + underlying :class:`~opensearch.Connection` class for serialization :arg body: body of the request, will be serialized using serializer and passed to the connection """ diff --git a/elasticsearch/_async/transport.pyi b/opensearch/_async/transport.pyi similarity index 100% rename from elasticsearch/_async/transport.pyi rename to opensearch/_async/transport.pyi diff --git a/elasticsearch/_version.py b/opensearch/_version.py similarity index 100% rename from elasticsearch/_version.py rename to opensearch/_version.py diff --git a/elasticsearch/client/__init__.py b/opensearch/client/__init__.py similarity index 98% rename from elasticsearch/client/__init__.py rename to opensearch/client/__init__.py index 5d6bea3d..063cc16b 100644 --- a/elasticsearch/client/__init__.py +++ b/opensearch/client/__init__.py @@ -42,23 +42,23 @@ from .snapshot import SnapshotClient from .tasks import TasksClient from .utils import SKIP_IN_PATH, _bulk_body, _make_path, _normalize_hosts, query_params -logger = logging.getLogger("elasticsearch") +logger = logging.getLogger("opensearch") -class Elasticsearch(object): +class OpenSearch(object): """ - Elasticsearch low-level client. Provides a straightforward mapping from + OpenSearch low-level client. Provides a straightforward mapping from Python to ES REST endpoints. The instance has attributes ``cat``, ``cluster``, ``indices``, ``ingest``, ``nodes``, ``snapshot`` and ``tasks`` that provide access to instances of - :class:`~elasticsearch.client.CatClient`, - :class:`~elasticsearch.client.ClusterClient`, - :class:`~elasticsearch.client.IndicesClient`, - :class:`~elasticsearch.client.IngestClient`, - :class:`~elasticsearch.client.NodesClient`, - :class:`~elasticsearch.client.SnapshotClient` and - :class:`~elasticsearch.client.TasksClient` respectively. This is the + :class:`~opensearch.client.CatClient`, + :class:`~opensearch.client.ClusterClient`, + :class:`~opensearch.client.IndicesClient`, + :class:`~opensearch.client.IngestClient`, + :class:`~opensearch.client.NodesClient`, + :class:`~opensearch.client.SnapshotClient` and + :class:`~opensearch.client.TasksClient` respectively. This is the preferred (and only supported) way to get access to those classes and their methods. @@ -66,15 +66,15 @@ class Elasticsearch(object): the ``connection_class`` parameter:: # create connection to localhost using the ThriftConnection - es = Elasticsearch(connection_class=ThriftConnection) + es = OpenSearch(connection_class=ThriftConnection) If you want to turn on :ref:`sniffing` you have several options (described - in :class:`~elasticsearch.Transport`):: + in :class:`~opensearch.Transport`):: # create connection that will automatically inspect the cluster to get # the list of active nodes. Start with nodes running on 'esnode1' and # 'esnode2' - es = Elasticsearch( + es = OpenSearch( ['esnode1', 'esnode2'], # sniff before doing anything sniff_on_start=True, @@ -89,16 +89,16 @@ class Elasticsearch(object): # connect to localhost directly and another node using SSL on port 443 # and an url_prefix. Note that ``port`` needs to be an int. - es = Elasticsearch([ + es = OpenSearch([ {'host': 'localhost'}, {'host': 'othernode', 'port': 443, 'url_prefix': 'es', 'use_ssl': True}, ]) If using SSL, there are several parameters that control how we deal with - certificates (see :class:`~elasticsearch.Urllib3HttpConnection` for + certificates (see :class:`~opensearch.Urllib3HttpConnection` for detailed description of the options):: - es = Elasticsearch( + es = OpenSearch( ['localhost:443', 'other_host:443'], # turn on SSL use_ssl=True, @@ -109,10 +109,10 @@ class Elasticsearch(object): ) If using SSL, but don't verify the certs, a warning message is showed - optionally (see :class:`~elasticsearch.Urllib3HttpConnection` for + optionally (see :class:`~opensearch.Urllib3HttpConnection` for detailed description of the options):: - es = Elasticsearch( + es = OpenSearch( ['localhost:443', 'other_host:443'], # turn on SSL use_ssl=True, @@ -123,10 +123,10 @@ class Elasticsearch(object): ) SSL client authentication is supported - (see :class:`~elasticsearch.Urllib3HttpConnection` for + (see :class:`~opensearch.Urllib3HttpConnection` for detailed description of the options):: - es = Elasticsearch( + es = OpenSearch( ['localhost:443', 'other_host:443'], # turn on SSL use_ssl=True, @@ -143,7 +143,7 @@ class Elasticsearch(object): Alternatively you can use RFC-1738 formatted URLs, as long as they are not in conflict with other options:: - es = Elasticsearch( + es = OpenSearch( [ 'http://user:secret@localhost:9200/', 'https://user:secret@other_host:443/production' @@ -152,11 +152,11 @@ class Elasticsearch(object): ) By default, `JSONSerializer - `_ + `_ is used to encode all outgoing requests. However, you can implement your own custom serializer:: - from elasticsearch.serializer import JSONSerializer + from opensearch.serializer import JSONSerializer class SetEncoder(JSONSerializer): def default(self, obj): @@ -166,7 +166,7 @@ class Elasticsearch(object): return 'CustomSomethingRepresentation' return JSONSerializer.default(self, obj) - es = Elasticsearch(serializer=SetEncoder()) + es = OpenSearch(serializer=SetEncoder()) """ @@ -174,16 +174,16 @@ class Elasticsearch(object): """ :arg hosts: list of nodes, or a single node, we should connect to. Node should be a dictionary ({"host": "localhost", "port": 9200}), - the entire dictionary will be passed to the :class:`~elasticsearch.Connection` + the entire dictionary will be passed to the :class:`~opensearch.Connection` class as kwargs, or a string in the format of ``host[:port]`` which will be translated to a dictionary automatically. If no value is given the - :class:`~elasticsearch.Connection` class defaults will be used. + :class:`~opensearch.Connection` class defaults will be used. - :arg transport_class: :class:`~elasticsearch.Transport` subclass to use. + :arg transport_class: :class:`~opensearch.Transport` subclass to use. :arg kwargs: any additional arguments will be passed on to the - :class:`~elasticsearch.Transport` class and, subsequently, to the - :class:`~elasticsearch.Connection` instances. + :class:`~opensearch.Transport` class and, subsequently, to the + :class:`~opensearch.Connection` instances. """ self.transport = transport_class(_normalize_hosts(hosts), **kwargs) @@ -210,7 +210,7 @@ class Elasticsearch(object): return "<{cls}({cons})>".format(cls=self.__class__.__name__, cons=cons) except Exception: # probably operating on custom transport and connection_pool, ignore - return super(Elasticsearch, self).__repr__() + return super(OpenSearch, self).__repr__() def __enter__(self): if hasattr(self.transport, "_async_call"): diff --git a/elasticsearch/client/__init__.pyi b/opensearch/client/__init__.pyi similarity index 99% rename from elasticsearch/client/__init__.pyi rename to opensearch/client/__init__.pyi index 86d697fe..455848ab 100644 --- a/elasticsearch/client/__init__.pyi +++ b/opensearch/client/__init__.pyi @@ -44,7 +44,7 @@ from .tasks import TasksClient logger: logging.Logger -class Elasticsearch(object): +class OpenSearch(object): transport: Transport cat: CatClient @@ -63,7 +63,7 @@ class Elasticsearch(object): **kwargs: Any, ) -> None: ... def __repr__(self) -> str: ... - def __enter__(self) -> "Elasticsearch": ... + def __enter__(self) -> "OpenSearch": ... def __exit__(self, *_: Any) -> None: ... def close(self) -> None: ... # AUTO-GENERATED-API-DEFINITIONS # diff --git a/elasticsearch/client/cat.py b/opensearch/client/cat.py similarity index 100% rename from elasticsearch/client/cat.py rename to opensearch/client/cat.py diff --git a/elasticsearch/client/cat.pyi b/opensearch/client/cat.pyi similarity index 100% rename from elasticsearch/client/cat.pyi rename to opensearch/client/cat.pyi diff --git a/elasticsearch/client/cluster.py b/opensearch/client/cluster.py similarity index 100% rename from elasticsearch/client/cluster.py rename to opensearch/client/cluster.py diff --git a/elasticsearch/client/cluster.pyi b/opensearch/client/cluster.pyi similarity index 100% rename from elasticsearch/client/cluster.pyi rename to opensearch/client/cluster.pyi diff --git a/elasticsearch/client/dangling_indices.py b/opensearch/client/dangling_indices.py similarity index 100% rename from elasticsearch/client/dangling_indices.py rename to opensearch/client/dangling_indices.py diff --git a/elasticsearch/client/dangling_indices.pyi b/opensearch/client/dangling_indices.pyi similarity index 100% rename from elasticsearch/client/dangling_indices.pyi rename to opensearch/client/dangling_indices.pyi diff --git a/elasticsearch/client/features.py b/opensearch/client/features.py similarity index 100% rename from elasticsearch/client/features.py rename to opensearch/client/features.py diff --git a/elasticsearch/client/features.pyi b/opensearch/client/features.pyi similarity index 100% rename from elasticsearch/client/features.pyi rename to opensearch/client/features.pyi diff --git a/elasticsearch/client/indices.py b/opensearch/client/indices.py similarity index 100% rename from elasticsearch/client/indices.py rename to opensearch/client/indices.py diff --git a/elasticsearch/client/indices.pyi b/opensearch/client/indices.pyi similarity index 100% rename from elasticsearch/client/indices.pyi rename to opensearch/client/indices.pyi diff --git a/elasticsearch/client/ingest.py b/opensearch/client/ingest.py similarity index 100% rename from elasticsearch/client/ingest.py rename to opensearch/client/ingest.py diff --git a/elasticsearch/client/ingest.pyi b/opensearch/client/ingest.pyi similarity index 100% rename from elasticsearch/client/ingest.pyi rename to opensearch/client/ingest.pyi diff --git a/elasticsearch/client/nodes.py b/opensearch/client/nodes.py similarity index 99% rename from elasticsearch/client/nodes.py rename to opensearch/client/nodes.py index 86b4f981..b3f57f2d 100644 --- a/elasticsearch/client/nodes.py +++ b/opensearch/client/nodes.py @@ -37,7 +37,7 @@ class NodesClient(NamespacedClient): :arg body: An object containing the password for the - elasticsearch keystore + opensearch keystore :arg node_id: A comma-separated list of node IDs to span the reload/reinit call. Should stay empty because reloading usually involves all cluster nodes. diff --git a/elasticsearch/client/nodes.pyi b/opensearch/client/nodes.pyi similarity index 100% rename from elasticsearch/client/nodes.pyi rename to opensearch/client/nodes.pyi diff --git a/elasticsearch/client/remote.py b/opensearch/client/remote.py similarity index 100% rename from elasticsearch/client/remote.py rename to opensearch/client/remote.py diff --git a/elasticsearch/client/remote.pyi b/opensearch/client/remote.pyi similarity index 100% rename from elasticsearch/client/remote.pyi rename to opensearch/client/remote.pyi diff --git a/elasticsearch/client/snapshot.py b/opensearch/client/snapshot.py similarity index 100% rename from elasticsearch/client/snapshot.py rename to opensearch/client/snapshot.py diff --git a/elasticsearch/client/snapshot.pyi b/opensearch/client/snapshot.pyi similarity index 100% rename from elasticsearch/client/snapshot.pyi rename to opensearch/client/snapshot.pyi diff --git a/elasticsearch/client/tasks.py b/opensearch/client/tasks.py similarity index 100% rename from elasticsearch/client/tasks.py rename to opensearch/client/tasks.py diff --git a/elasticsearch/client/tasks.pyi b/opensearch/client/tasks.pyi similarity index 100% rename from elasticsearch/client/tasks.pyi rename to opensearch/client/tasks.pyi diff --git a/elasticsearch/client/utils.py b/opensearch/client/utils.py similarity index 99% rename from elasticsearch/client/utils.py rename to opensearch/client/utils.py index d4e72ea5..a369cb78 100644 --- a/elasticsearch/client/utils.py +++ b/opensearch/client/utils.py @@ -40,7 +40,7 @@ SKIP_IN_PATH = (None, "", b"", [], ()) def _normalize_hosts(hosts): """ Helper function to transform hosts argument to - :class:`~elasticsearch.Elasticsearch` to a list of dicts. + :class:`~opensearch.OpenSearch` to a list of dicts. """ # if hosts are empty, just defer to defaults down the line if hosts is None: diff --git a/elasticsearch/client/utils.pyi b/opensearch/client/utils.pyi similarity index 93% rename from elasticsearch/client/utils.pyi rename to opensearch/client/utils.pyi index d091f90f..4924fed9 100644 --- a/elasticsearch/client/utils.pyi +++ b/opensearch/client/utils.pyi @@ -38,7 +38,7 @@ from typing import ( Union, ) -from ..client import Elasticsearch +from ..client import OpenSearch from ..serializer import Serializer from ..transport import Transport @@ -61,7 +61,7 @@ def _bulk_body( ) -> str: ... class NamespacedClient: - client: Elasticsearch - def __init__(self, client: Elasticsearch) -> None: ... + client: OpenSearch + def __init__(self, client: OpenSearch) -> None: ... @property def transport(self) -> Transport: ... diff --git a/elasticsearch/compat.py b/opensearch/compat.py similarity index 100% rename from elasticsearch/compat.py rename to opensearch/compat.py diff --git a/elasticsearch/compat.pyi b/opensearch/compat.pyi similarity index 100% rename from elasticsearch/compat.pyi rename to opensearch/compat.pyi diff --git a/elasticsearch/connection/__init__.py b/opensearch/connection/__init__.py similarity index 100% rename from elasticsearch/connection/__init__.py rename to opensearch/connection/__init__.py diff --git a/elasticsearch/connection/__init__.pyi b/opensearch/connection/__init__.pyi similarity index 100% rename from elasticsearch/connection/__init__.pyi rename to opensearch/connection/__init__.pyi diff --git a/elasticsearch/connection/base.py b/opensearch/connection/base.py similarity index 94% rename from elasticsearch/connection/base.py rename to opensearch/connection/base.py index 3bf57cd7..91c44d7c 100644 --- a/elasticsearch/connection/base.py +++ b/opensearch/connection/base.py @@ -41,17 +41,17 @@ except ImportError: from .. import __version__, __versionstr__ from ..exceptions import ( HTTP_EXCEPTIONS, - ElasticsearchWarning, ImproperlyConfigured, + OpenSearchWarning, TransportError, ) -logger = logging.getLogger("elasticsearch") +logger = logging.getLogger("opensearch") -# create the elasticsearch.trace logger, but only set propagate to False if the +# create the opensearch.trace logger, but only set propagate to False if the # logger hasn't already been configured -_tracer_already_configured = "elasticsearch.trace" in logging.Logger.manager.loggerDict -tracer = logging.getLogger("elasticsearch.trace") +_tracer_already_configured = "opensearch.trace" in logging.Logger.manager.loggerDict +tracer = logging.getLogger("opensearch.trace") if not _tracer_already_configured: tracer.propagate = False @@ -60,7 +60,7 @@ _WARNING_RE = re.compile(r"\"([^\"]*)\"") class Connection(object): """ - Class responsible for maintaining a connection to an Elasticsearch node. It + Class responsible for maintaining a connection to an OpenSearch node. It holds persistent connection pool to it and it's main interface (`perform_request`) is thread-safe. @@ -69,7 +69,7 @@ class Connection(object): :arg host: hostname of the node (default: localhost) :arg port: port to use (integer, default: 9200) :arg use_ssl: use ssl for the connection if `True` - :arg url_prefix: optional url prefix for elasticsearch + :arg url_prefix: optional url prefix for opensearch :arg timeout: default timeout in seconds (float, default: 10) :arg http_compress: Use gzip compression :arg cloud_id: The Cloud ID from ElasticCloud. Convenient way to connect to cloud instances. @@ -134,7 +134,7 @@ class Connection(object): if os.getenv("ELASTIC_CLIENT_APIVERSIONING") == "1": self.headers.setdefault( "accept", - "application/vnd.elasticsearch+json;compatible-with=%s" + "application/vnd.opensearch+json;compatible-with=%s" % (str(__version__[0]),), ) @@ -198,7 +198,7 @@ class Connection(object): return # Grab only the message from each header, the rest is discarded. - # Format is: '(number) Elasticsearch-(version)-(instance) "(message)"' + # Format is: '(number) OpenSearch-(version)-(instance) "(message)"' warning_messages = [] for header in warning_headers: # Because 'Requests' does it's own folding of multiple HTTP headers @@ -214,7 +214,7 @@ class Connection(object): warning_messages.append(header) for message in warning_messages: - warnings.warn(message, category=ElasticsearchWarning) + warnings.warn(message, category=OpenSearchWarning) def _pretty_json(self, data): # pretty JSON in tracer curl logs @@ -341,7 +341,7 @@ class Connection(object): ) def _get_default_user_agent(self): - return "elasticsearch-py/%s (Python %s)" % (__versionstr__, python_version()) + return "opensearch-py/%s (Python %s)" % (__versionstr__, python_version()) def _get_api_key_header_val(self, api_key): """ diff --git a/elasticsearch/connection/base.pyi b/opensearch/connection/base.pyi similarity index 100% rename from elasticsearch/connection/base.pyi rename to opensearch/connection/base.pyi diff --git a/elasticsearch/connection/http_requests.py b/opensearch/connection/http_requests.py similarity index 100% rename from elasticsearch/connection/http_requests.py rename to opensearch/connection/http_requests.py diff --git a/elasticsearch/connection/http_requests.pyi b/opensearch/connection/http_requests.pyi similarity index 100% rename from elasticsearch/connection/http_requests.pyi rename to opensearch/connection/http_requests.pyi diff --git a/elasticsearch/connection/http_urllib3.py b/opensearch/connection/http_urllib3.py similarity index 99% rename from elasticsearch/connection/http_urllib3.py rename to opensearch/connection/http_urllib3.py index 27cd35e8..e0cd54a4 100644 --- a/elasticsearch/connection/http_urllib3.py +++ b/opensearch/connection/http_urllib3.py @@ -77,7 +77,7 @@ class Urllib3HttpConnection(Connection): :arg host: hostname of the node (default: localhost) :arg port: port to use (integer, default: 9200) - :arg url_prefix: optional url prefix for elasticsearch + :arg url_prefix: optional url prefix for opensearch :arg timeout: default timeout in seconds (float, default: 10) :arg http_auth: optional http auth information as either ':' separated string or a tuple diff --git a/elasticsearch/connection/http_urllib3.pyi b/opensearch/connection/http_urllib3.pyi similarity index 100% rename from elasticsearch/connection/http_urllib3.pyi rename to opensearch/connection/http_urllib3.pyi diff --git a/elasticsearch/connection/pooling.py b/opensearch/connection/pooling.py similarity index 100% rename from elasticsearch/connection/pooling.py rename to opensearch/connection/pooling.py diff --git a/elasticsearch/connection/pooling.pyi b/opensearch/connection/pooling.pyi similarity index 100% rename from elasticsearch/connection/pooling.pyi rename to opensearch/connection/pooling.pyi diff --git a/elasticsearch/connection_pool.py b/opensearch/connection_pool.py similarity index 95% rename from elasticsearch/connection_pool.py rename to opensearch/connection_pool.py index 8c440761..5ed25959 100644 --- a/elasticsearch/connection_pool.py +++ b/opensearch/connection_pool.py @@ -36,7 +36,7 @@ except ImportError: from .exceptions import ImproperlyConfigured -logger = logging.getLogger("elasticsearch") +logger = logging.getLogger("opensearch") class ConnectionSelector(object): @@ -48,7 +48,7 @@ class ConnectionSelector(object): *currently* live connections to choose from. The options dictionary is the one that has been passed to - :class:`~elasticsearch.Transport` as `hosts` param and the same that is + :class:`~opensearch.Transport` as `hosts` param and the same that is used to construct the Connection object itself. When the Connection was created from information retrieved from the cluster via the sniffing process it will be the dictionary returned by the `host_info_callback`. @@ -99,11 +99,11 @@ class RoundRobinSelector(ConnectionSelector): class ConnectionPool(object): """ - Container holding the :class:`~elasticsearch.Connection` instances, + Container holding the :class:`~opensearch.Connection` instances, managing the selection process (via a - :class:`~elasticsearch.ConnectionSelector`) and dead connections. + :class:`~opensearch.ConnectionSelector`) and dead connections. - It's only interactions are with the :class:`~elasticsearch.Transport` class + It's only interactions are with the :class:`~opensearch.Transport` class that drives all the actions within `ConnectionPool`. Initially connections are stored on the class as a list and, along with the @@ -131,12 +131,12 @@ class ConnectionPool(object): ): """ :arg connections: list of tuples containing the - :class:`~elasticsearch.Connection` instance and it's options + :class:`~opensearch.Connection` instance and it's options :arg dead_timeout: number of seconds a connection should be retired for after a failure, increases on consecutive failures :arg timeout_cutoff: number of consecutive failures after which the timeout doesn't increase - :arg selector_class: :class:`~elasticsearch.ConnectionSelector` + :arg selector_class: :class:`~opensearch.ConnectionSelector` subclass to use if more than one connection is live :arg randomize_hosts: shuffle the list of connections upon arrival to avoid dog piling effect across processes diff --git a/elasticsearch/connection_pool.pyi b/opensearch/connection_pool.pyi similarity index 100% rename from elasticsearch/connection_pool.pyi rename to opensearch/connection_pool.pyi diff --git a/elasticsearch/exceptions.py b/opensearch/exceptions.py similarity index 91% rename from elasticsearch/exceptions.py rename to opensearch/exceptions.py index b9d720d4..203e6ba2 100644 --- a/elasticsearch/exceptions.py +++ b/opensearch/exceptions.py @@ -26,7 +26,7 @@ __all__ = [ "ImproperlyConfigured", - "ElasticsearchException", + "OpenSearchException", "SerializationError", "TransportError", "NotFoundError", @@ -46,21 +46,21 @@ class ImproperlyConfigured(Exception): """ -class ElasticsearchException(Exception): +class OpenSearchException(Exception): """ Base class for all exceptions raised by this package's operations (doesn't - apply to :class:`~elasticsearch.ImproperlyConfigured`). + apply to :class:`~opensearch.ImproperlyConfigured`). """ -class SerializationError(ElasticsearchException): +class SerializationError(OpenSearchException): """ Data passed in failed to serialize properly in the ``Serializer`` being used. """ -class TransportError(ElasticsearchException): +class TransportError(OpenSearchException): """ Exception raised when ES returns a non-OK (>=400) HTTP status code. Or when an actual connection error happens; in that case the ``status_code`` will @@ -116,7 +116,7 @@ class TransportError(ElasticsearchException): class ConnectionError(TransportError): """ Error raised when there was an exception while talking to ES. Original - exception from the underlying :class:`~elasticsearch.Connection` + exception from the underlying :class:`~opensearch.Connection` implementation is available as ``.info``. """ @@ -162,16 +162,16 @@ class AuthorizationException(TransportError): """Exception representing a 403 status code.""" -class ElasticsearchWarning(Warning): +class OpenSearchWarning(Warning): """Warning that is raised when a deprecated option or incorrect usage is flagged via the 'Warning' HTTP header. """ -# Alias of 'ElasticsearchWarning' for backwards compatibility. +# Alias of 'OpenSearchWarning' for backwards compatibility. # Additional functionality was added to the 'Warning' HTTP header # not related to deprecations. -ElasticsearchDeprecationWarning = ElasticsearchWarning +OpenSearchDeprecationWarning = OpenSearchWarning # more generic mappings from status_code to python exceptions diff --git a/elasticsearch/exceptions.pyi b/opensearch/exceptions.pyi similarity index 85% rename from elasticsearch/exceptions.pyi rename to opensearch/exceptions.pyi index 105d6b17..66bc4787 100644 --- a/elasticsearch/exceptions.pyi +++ b/opensearch/exceptions.pyi @@ -27,10 +27,10 @@ from typing import Any, Dict, Union class ImproperlyConfigured(Exception): ... -class ElasticsearchException(Exception): ... -class SerializationError(ElasticsearchException): ... +class OpenSearchException(Exception): ... +class SerializationError(OpenSearchException): ... -class TransportError(ElasticsearchException): +class TransportError(OpenSearchException): @property def status_code(self) -> Union[str, int]: ... @property @@ -52,8 +52,8 @@ class ConflictError(TransportError): ... class RequestError(TransportError): ... class AuthenticationException(TransportError): ... class AuthorizationException(TransportError): ... -class ElasticsearchWarning(Warning): ... +class OpenSearchWarning(Warning): ... -ElasticsearchDeprecationWarning = ElasticsearchWarning +OpenSearchDeprecationWarning = OpenSearchWarning -HTTP_EXCEPTIONS: Dict[int, ElasticsearchException] +HTTP_EXCEPTIONS: Dict[int, OpenSearchException] diff --git a/elasticsearch/helpers/__init__.py b/opensearch/helpers/__init__.py similarity index 100% rename from elasticsearch/helpers/__init__.py rename to opensearch/helpers/__init__.py diff --git a/elasticsearch/helpers/__init__.pyi b/opensearch/helpers/__init__.pyi similarity index 100% rename from elasticsearch/helpers/__init__.pyi rename to opensearch/helpers/__init__.pyi diff --git a/elasticsearch/helpers/actions.py b/opensearch/helpers/actions.py similarity index 93% rename from elasticsearch/helpers/actions.py rename to opensearch/helpers/actions.py index 2b84e7af..fa2a822d 100644 --- a/elasticsearch/helpers/actions.py +++ b/opensearch/helpers/actions.py @@ -32,14 +32,14 @@ from ..compat import Mapping, Queue, map, string_types from ..exceptions import TransportError from .errors import BulkIndexError, ScanError -logger = logging.getLogger("elasticsearch.helpers") +logger = logging.getLogger("opensearch.helpers") def expand_action(data): """ From one document or action definition passed in by the user extract the - action/data lines needed for elasticsearch's - :meth:`~elasticsearch.Elasticsearch.bulk` api. + action/data lines needed for opensearch's + :meth:`~opensearch.OpenSearch.bulk` api. """ # when given a string, assume user wants to index raw json if isinstance(data, string_types): @@ -237,7 +237,7 @@ def _process_bulk_chunk( **kwargs ): """ - Send a bulk request to elasticsearch and process the output. + Send a bulk request to opensearch and process the output. """ kwargs = _add_helper_meta_to_kwargs(kwargs, "bp") @@ -293,7 +293,7 @@ def streaming_bulk( """ Streaming bulk consumes actions from the iterable passed in and yields results per action. For non-streaming usecases use - :func:`~elasticsearch.helpers.bulk` which is a wrapper around streaming + :func:`~opensearch.helpers.bulk` which is a wrapper around streaming bulk that returns summary information about the bulk operation once the entire input is consumed and sent. @@ -303,7 +303,7 @@ def streaming_bulk( every subsequent rejection for the same chunk, for double the time every time up to ``max_backoff`` seconds. - :arg client: instance of :class:`~elasticsearch.Elasticsearch` to use + :arg client: instance of :class:`~opensearch.OpenSearch` to use :arg actions: iterable containing the actions to be executed :arg chunk_size: number of docs in one chunk sent to es (default: 500) :arg max_chunk_bytes: the maximum size of the request in bytes (default: 100MB) @@ -382,9 +382,9 @@ def streaming_bulk( def bulk(client, actions, stats_only=False, ignore_status=(), *args, **kwargs): """ - Helper for the :meth:`~elasticsearch.Elasticsearch.bulk` api that provides + Helper for the :meth:`~opensearch.OpenSearch.bulk` api that provides a more human friendly interface - it consumes an iterator of actions and - sends them to elasticsearch in chunks. It returns a tuple with summary + sends them to opensearch in chunks. It returns a tuple with summary information - number of successfully executed actions and either list of errors or number of errors if ``stats_only`` is set to ``True``. Note that by default we raise a ``BulkIndexError`` when we encounter an error so @@ -394,19 +394,19 @@ def bulk(client, actions, stats_only=False, ignore_status=(), *args, **kwargs): When errors are being collected original document data is included in the error dictionary which can lead to an extra high memory usage. If you need to process a lot of data and want to ignore/collect errors please consider - using the :func:`~elasticsearch.helpers.streaming_bulk` helper which will + using the :func:`~opensearch.helpers.streaming_bulk` helper which will just return the errors and not store them in memory. - :arg client: instance of :class:`~elasticsearch.Elasticsearch` to use + :arg client: instance of :class:`~opensearch.OpenSearch` to use :arg actions: iterator containing the actions :arg stats_only: if `True` only report number of successful/failed operations instead of just number of successful and a list of error responses :arg ignore_status: list of HTTP status code that you want to ignore Any additional keyword arguments will be passed to - :func:`~elasticsearch.helpers.streaming_bulk` which is used to execute - the operation, see :func:`~elasticsearch.helpers.streaming_bulk` for more + :func:`~opensearch.helpers.streaming_bulk` which is used to execute + the operation, see :func:`~opensearch.helpers.streaming_bulk` for more accepted parameters. """ success, failed = 0, 0 @@ -445,7 +445,7 @@ def parallel_bulk( """ Parallel version of the bulk helper run in multiple threads at once. - :arg client: instance of :class:`~elasticsearch.Elasticsearch` to use + :arg client: instance of :class:`~opensearch.OpenSearch` to use :arg actions: iterator containing the actions :arg thread_count: size of the threadpool to use for the bulk requests :arg chunk_size: number of docs in one chunk sent to es (default: 500) @@ -515,7 +515,7 @@ def scan( ): """ Simple abstraction on top of the - :meth:`~elasticsearch.Elasticsearch.scroll` api - a simple iterator that + :meth:`~opensearch.OpenSearch.scroll` api - a simple iterator that yields all hits as returned by underlining scroll requests. By default scan does not return results in any pre-determined order. To @@ -524,8 +524,8 @@ def scan( may be an expensive operation and will negate the performance benefits of using ``scan``. - :arg client: instance of :class:`~elasticsearch.Elasticsearch` to use - :arg query: body for the :meth:`~elasticsearch.Elasticsearch.search` api + :arg client: instance of :class:`~opensearch.OpenSearch` to use + :arg query: body for the :meth:`~opensearch.OpenSearch.search` api :arg scroll: Specify how long a consistent view of the index should be maintained for scrolled search :arg raise_on_error: raises an exception (``ScanError``) if an error is @@ -540,10 +540,10 @@ def scan( scroll API at the end of the method on completion or error, defaults to true. :arg scroll_kwargs: additional kwargs to be passed to - :meth:`~elasticsearch.Elasticsearch.scroll` + :meth:`~opensearch.OpenSearch.scroll` Any additional keyword arguments will be passed to the initial - :meth:`~elasticsearch.Elasticsearch.search` call:: + :meth:`~opensearch.OpenSearch.search` call:: scan(es, query={"query": {"match": {"title": "python"}}}, @@ -640,8 +640,8 @@ def reindex( to another, potentially (if `target_client` is specified) on a different cluster. If you don't specify the query you will reindex all the documents. - Since ``2.3`` a :meth:`~elasticsearch.Elasticsearch.reindex` api is - available as part of elasticsearch itself. It is recommended to use the api + Since ``2.3`` a :meth:`~opensearch.OpenSearch.reindex` api is + available as part of opensearch itself. It is recommended to use the api instead of this helper wherever possible. The helper is here mostly for backwards compatibility and for situations where more flexibility is needed. @@ -650,20 +650,20 @@ def reindex( This helper doesn't transfer mappings, just the data. - :arg client: instance of :class:`~elasticsearch.Elasticsearch` to use (for + :arg client: instance of :class:`~opensearch.OpenSearch` to use (for read if `target_client` is specified as well) :arg source_index: index (or list of indices) to read documents from :arg target_index: name of the index in the target cluster to populate - :arg query: body for the :meth:`~elasticsearch.Elasticsearch.search` api + :arg query: body for the :meth:`~opensearch.OpenSearch.search` api :arg target_client: optional, is specified will be used for writing (thus enabling reindex between clusters) :arg chunk_size: number of docs in one chunk sent to es (default: 500) :arg scroll: Specify how long a consistent view of the index should be maintained for scrolled search :arg scan_kwargs: additional kwargs to be passed to - :func:`~elasticsearch.helpers.scan` + :func:`~opensearch.helpers.scan` :arg bulk_kwargs: additional kwargs to be passed to - :func:`~elasticsearch.helpers.bulk` + :func:`~opensearch.helpers.bulk` """ target_client = client if target_client is None else target_client docs = scan(client, query=query, index=source_index, scroll=scroll, **scan_kwargs) diff --git a/elasticsearch/helpers/actions.pyi b/opensearch/helpers/actions.pyi similarity index 93% rename from elasticsearch/helpers/actions.pyi rename to opensearch/helpers/actions.pyi index 400194a5..ecc9447b 100644 --- a/elasticsearch/helpers/actions.pyi +++ b/opensearch/helpers/actions.pyi @@ -40,7 +40,7 @@ from typing import ( Union, ) -from ..client import Elasticsearch +from ..client import OpenSearch from ..serializer import Serializer logger: logging.Logger @@ -50,7 +50,7 @@ def _chunk_actions( actions: Any, chunk_size: int, max_chunk_bytes: int, serializer: Serializer ) -> Generator[Any, None, None]: ... def _process_bulk_chunk( - client: Elasticsearch, + client: OpenSearch, bulk_actions: Any, bulk_data: Any, raise_on_exception: bool = ..., @@ -59,7 +59,7 @@ def _process_bulk_chunk( **kwargs: Any ) -> Generator[Tuple[bool, Any], None, None]: ... def streaming_bulk( - client: Elasticsearch, + client: OpenSearch, actions: Union[Iterable[Any], AsyncIterable[Any]], chunk_size: int = ..., max_chunk_bytes: int = ..., @@ -75,7 +75,7 @@ def streaming_bulk( **kwargs: Any ) -> Generator[Tuple[bool, Any], None, None]: ... def bulk( - client: Elasticsearch, + client: OpenSearch, actions: Iterable[Any], stats_only: bool = ..., ignore_status: Optional[Union[int, Collection[int]]] = ..., @@ -83,7 +83,7 @@ def bulk( **kwargs: Any ) -> Tuple[int, Union[int, List[Any]]]: ... def parallel_bulk( - client: Elasticsearch, + client: OpenSearch, actions: Iterable[Any], thread_count: int = ..., chunk_size: int = ..., @@ -95,7 +95,7 @@ def parallel_bulk( **kwargs: Any ) -> Generator[Tuple[bool, Any], None, None]: ... def scan( - client: Elasticsearch, + client: OpenSearch, query: Optional[Any] = ..., scroll: str = ..., raise_on_error: bool = ..., @@ -107,11 +107,11 @@ def scan( **kwargs: Any ) -> Generator[Any, None, None]: ... def reindex( - client: Elasticsearch, + client: OpenSearch, source_index: Union[str, Collection[str]], target_index: str, query: Any = ..., - target_client: Optional[Elasticsearch] = ..., + target_client: Optional[OpenSearch] = ..., chunk_size: int = ..., scroll: str = ..., scan_kwargs: Optional[Mapping[str, Any]] = ..., diff --git a/elasticsearch/helpers/errors.py b/opensearch/helpers/errors.py similarity index 90% rename from elasticsearch/helpers/errors.py rename to opensearch/helpers/errors.py index b263831f..9c688d82 100644 --- a/elasticsearch/helpers/errors.py +++ b/opensearch/helpers/errors.py @@ -24,17 +24,17 @@ # specific language governing permissions and limitations # under the License. -from ..exceptions import ElasticsearchException +from ..exceptions import OpenSearchException -class BulkIndexError(ElasticsearchException): +class BulkIndexError(OpenSearchException): @property def errors(self): """List of errors from execution of the last chunk.""" return self.args[1] -class ScanError(ElasticsearchException): +class ScanError(OpenSearchException): def __init__(self, scroll_id, *args, **kwargs): super(ScanError, self).__init__(*args, **kwargs) # type: ignore self.scroll_id = scroll_id diff --git a/elasticsearch/helpers/errors.pyi b/opensearch/helpers/errors.pyi similarity index 90% rename from elasticsearch/helpers/errors.pyi rename to opensearch/helpers/errors.pyi index 347114e1..bed92df7 100644 --- a/elasticsearch/helpers/errors.pyi +++ b/opensearch/helpers/errors.pyi @@ -26,12 +26,12 @@ from typing import Any, List -from ..exceptions import ElasticsearchException +from ..exceptions import OpenSearchException -class BulkIndexError(ElasticsearchException): +class BulkIndexError(OpenSearchException): @property def errors(self) -> List[Any]: ... -class ScanError(ElasticsearchException): +class ScanError(OpenSearchException): scroll_id: str def __init__(self, scroll_id: str, *args: Any, **kwargs: Any) -> None: ... diff --git a/elasticsearch/helpers/test.py b/opensearch/helpers/test.py similarity index 86% rename from elasticsearch/helpers/test.py rename to opensearch/helpers/test.py index 289212f0..6b8931d4 100644 --- a/elasticsearch/helpers/test.py +++ b/opensearch/helpers/test.py @@ -31,13 +31,13 @@ import time from os.path import abspath, dirname, join from unittest import SkipTest, TestCase -from elasticsearch import Elasticsearch -from elasticsearch.exceptions import ConnectionError +from opensearch import OpenSearch +from opensearch.exceptions import ConnectionError -if "ELASTICSEARCH_URL" in os.environ: - ELASTICSEARCH_URL = os.environ["ELASTICSEARCH_URL"] +if "OPENSEARCH_URL" in os.environ: + OPENSEARCH_URL = os.environ["OPENSEARCH_URL"] else: - ELASTICSEARCH_URL = "https://elastic:changeme@localhost:9200" + OPENSEARCH_URL = "https://elastic:changeme@localhost:9200" CA_CERTS = join(dirname(dirname(dirname(abspath(__file__)))), ".ci/certs/ca.pem") @@ -47,14 +47,14 @@ def get_test_client(nowait=False, **kwargs): kw = {"timeout": 30, "ca_certs": CA_CERTS} if "PYTHON_CONNECTION_CLASS" in os.environ: - from elasticsearch import connection + from opensearch import connection kw["connection_class"] = getattr( connection, os.environ["PYTHON_CONNECTION_CLASS"] ) kw.update(kwargs) - client = Elasticsearch(ELASTICSEARCH_URL, **kw) + client = OpenSearch(OPENSEARCH_URL, **kw) # wait for yellow status for _ in range(1 if nowait else 100): @@ -65,10 +65,10 @@ def get_test_client(nowait=False, **kwargs): time.sleep(0.1) else: # timeout - raise SkipTest("Elasticsearch failed to start.") + raise SkipTest("OpenSearch failed to start.") -class ElasticsearchTestCase(TestCase): +class OpenSearchTestCase(TestCase): @staticmethod def _get_client(): return get_test_client() diff --git a/elasticsearch/helpers/test.pyi b/opensearch/helpers/test.pyi similarity index 86% rename from elasticsearch/helpers/test.pyi rename to opensearch/helpers/test.pyi index 21db07b9..4ae26a51 100644 --- a/elasticsearch/helpers/test.pyi +++ b/opensearch/helpers/test.pyi @@ -27,17 +27,17 @@ from typing import Any, Tuple from unittest import TestCase -from ..client import Elasticsearch +from ..client import OpenSearch -ELASTICSEARCH_URL: str +OPENSEARCH_URL: str CA_CERTS: str -def get_test_client(nowait: bool = ..., **kwargs: Any) -> Elasticsearch: ... +def get_test_client(nowait: bool = ..., **kwargs: Any) -> OpenSearch: ... def _get_version(version_string: str) -> Tuple[int, ...]: ... -class ElasticsearchTestCase(TestCase): +class OpenSearchTestCase(TestCase): @staticmethod - def _get_client() -> Elasticsearch: ... + def _get_client() -> OpenSearch: ... @classmethod def setup_class(cls) -> None: ... def teardown_method(self, _: Any) -> None: ... diff --git a/elasticsearch/py.typed b/opensearch/py.typed similarity index 100% rename from elasticsearch/py.typed rename to opensearch/py.typed diff --git a/elasticsearch/serializer.py b/opensearch/serializer.py similarity index 97% rename from elasticsearch/serializer.py rename to opensearch/serializer.py index c2486f5e..2f42798d 100644 --- a/elasticsearch/serializer.py +++ b/opensearch/serializer.py @@ -165,9 +165,9 @@ class Deserializer(object): else: # split out 'charset' and 'compatible-width' options mimetype = mimetype.partition(";")[0].strip() - # Treat 'application/vnd.elasticsearch+json' + # Treat 'application/vnd.opensearch+json' # as application/json for compatibility. - if mimetype == "application/vnd.elasticsearch+json": + if mimetype == "application/vnd.opensearch+json": mimetype = "application/json" try: deserializer = self.serializers[mimetype] diff --git a/elasticsearch/serializer.pyi b/opensearch/serializer.pyi similarity index 100% rename from elasticsearch/serializer.pyi rename to opensearch/serializer.pyi diff --git a/elasticsearch/transport.py b/opensearch/transport.py similarity index 96% rename from elasticsearch/transport.py rename to opensearch/transport.py index a6849c72..c630f4b0 100644 --- a/elasticsearch/transport.py +++ b/opensearch/transport.py @@ -48,7 +48,7 @@ def get_host_info(node_info, host): `None` is returned this node will be skipped. Useful for filtering nodes (by proximity for example) or if additional - information needs to be provided for the :class:`~elasticsearch.Connection` + information needs to be provided for the :class:`~opensearch.Connection` class. By default master only nodes are filtered out since they shouldn't typically be used for API operations. @@ -94,8 +94,8 @@ class Transport(object): """ :arg hosts: list of dictionaries, each containing keyword arguments to create a `connection_class` instance - :arg connection_class: subclass of :class:`~elasticsearch.Connection` to use - :arg connection_pool_class: subclass of :class:`~elasticsearch.ConnectionPool` to use + :arg connection_class: subclass of :class:`~opensearch.Connection` to use + :arg connection_pool_class: subclass of :class:`~opensearch.ConnectionPool` to use :arg host_info_callback: callback responsible for taking the node information from `/_cluster/nodes`, along with already extracted information, and producing a list of arguments (same as `hosts` parameter) @@ -209,7 +209,7 @@ class Transport(object): def add_connection(self, host): """ - Create a new :class:`~elasticsearch.Connection` instance and add it to the pool. + Create a new :class:`~opensearch.Connection` instance and add it to the pool. :arg host: kwargs that will be used to create the instance """ @@ -220,7 +220,7 @@ class Transport(object): """ Instantiate all the connections and create new connection pool to hold them. Tries to identify unchanged hosts and re-use existing - :class:`~elasticsearch.Connection` instances. + :class:`~opensearch.Connection` instances. :arg hosts: same as `__init__` """ @@ -252,8 +252,8 @@ class Transport(object): def get_connection(self): """ - Retrieve a :class:`~elasticsearch.Connection` instance from the - :class:`~elasticsearch.ConnectionPool` instance. + Retrieve a :class:`~opensearch.Connection` instance from the + :class:`~opensearch.ConnectionPool` instance. """ if self.sniffer_timeout: if time.time() >= self.last_sniff + self.sniffer_timeout: @@ -357,7 +357,7 @@ class Transport(object): Mark a connection as dead (failed) in the connection pool. If sniffing on failure is enabled this will initiate the sniffing process. - :arg connection: instance of :class:`~elasticsearch.Connection` that failed + :arg connection: instance of :class:`~opensearch.Connection` that failed """ # mark as dead even when sniffing to avoid hitting this host during the sniff process self.connection_pool.mark_dead(connection) @@ -379,9 +379,9 @@ class Transport(object): :arg method: HTTP method to use :arg url: absolute url (without host) to target :arg headers: dictionary of headers, will be handed over to the - underlying :class:`~elasticsearch.Connection` class + underlying :class:`~opensearch.Connection` class :arg params: dictionary of query parameters, will be handed over to the - underlying :class:`~elasticsearch.Connection` class for serialization + underlying :class:`~opensearch.Connection` class for serialization :arg body: body of the request, will be serialized using serializer and passed to the connection """ diff --git a/elasticsearch/transport.pyi b/opensearch/transport.pyi similarity index 100% rename from elasticsearch/transport.pyi rename to opensearch/transport.pyi diff --git a/elasticsearch/utils.py b/opensearch/utils.py similarity index 100% rename from elasticsearch/utils.py rename to opensearch/utils.py diff --git a/elasticsearch/utils.pyi b/opensearch/utils.pyi similarity index 100% rename from elasticsearch/utils.pyi rename to opensearch/utils.pyi diff --git a/setup.py b/setup.py index 5ba101f8..208e3c77 100644 --- a/setup.py +++ b/setup.py @@ -30,7 +30,7 @@ from os.path import abspath, dirname, join from setuptools import find_packages, setup -package_name = "elasticsearch" +package_name = "opensearch" base_dir = abspath(dirname(__file__)) with open(join(base_dir, package_name, "_version.py")) as f: @@ -43,7 +43,7 @@ with open(join(base_dir, "README.md")) as f: packages = [ package - for package in find_packages(where=".", exclude=("test_elasticsearch*",)) + for package in find_packages(where=".", exclude=("test_opensearch*",)) if package == package_name or package.startswith(package_name + ".") ] @@ -68,7 +68,7 @@ setup( name=package_name, description="Python client for Elasticsearch", license="Apache-2.0", - url="https://github.com/elastic/elasticsearch-py", + url="https://github.com/opensearch-project/opensearch-py", long_description=long_description, long_description_content_type="text/x-rst", version=package_version, @@ -77,12 +77,12 @@ setup( maintainer="Seth Michael Larson", maintainer_email="seth.larson@elastic.co", project_urls={ - "Documentation": "https://elasticsearch-py.readthedocs.io", - "Source Code": "https://github.com/elastic/elasticsearch-py", - "Issue Tracker": "https://github.com/elastic/elasticsearch-py/issues", + "Documentation": "https://opensearch-py.readthedocs.io", + "Source Code": "https://github.com/opensearch-project/opensearch-py", + "Issue Tracker": "https://github.com/opensearch-project/opensearch-py/issues", }, packages=packages, - package_data={"elasticsearch": ["py.typed", "*.pyi"]}, + package_data={"opensearch": ["py.typed", "*.pyi"]}, include_package_data=True, zip_safe=False, classifiers=[ @@ -105,7 +105,7 @@ setup( ], python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, <4", install_requires=install_requires, - test_suite="test_elasticsearch.run_tests.run_all", + test_suite="test_opensearch.run_tests.run_all", tests_require=tests_require, extras_require={ "develop": tests_require + docs_require + generate_require, diff --git a/test_elasticsearch/__init__.py b/test_opensearch/__init__.py similarity index 100% rename from test_elasticsearch/__init__.py rename to test_opensearch/__init__.py diff --git a/test_elasticsearch/run_tests.py b/test_opensearch/run_tests.py similarity index 88% rename from test_elasticsearch/run_tests.py rename to test_opensearch/run_tests.py index a9f5a216..514cbb66 100755 --- a/test_elasticsearch/run_tests.py +++ b/test_opensearch/run_tests.py @@ -59,19 +59,19 @@ def fetch_es_repo(): if environ.get("TEST_ES_NOFETCH", False): return - from test_elasticsearch.test_cases import SkipTest - from test_elasticsearch.test_server import get_client + from test_opensearch.test_cases import SkipTest + from test_opensearch.test_server import get_client # find out the sha of the running es try: es = get_client() sha = es.info()["version"]["build_hash"] except (SkipTest, KeyError): - print("No running elasticsearch >1.X server...") + print("No running opensearch >1.X server...") return # fetch new commits to be sure... - print("Fetching elasticsearch repo...") + print("Fetching opensearch repo...") subprocess.check_call( "cd %s && git fetch https://github.com/opensearch-project/opensearch.git" % repo_path, @@ -92,11 +92,11 @@ def run_all(argv=None): # always insert coverage when running tests if argv is None: junit_xml = join( - abspath(dirname(dirname(__file__))), "junit", "elasticsearch-py-junit.xml" + abspath(dirname(dirname(__file__))), "junit", "opensearch-py-junit.xml" ) argv = [ "pytest", - "--cov=elasticsearch", + "--cov=opensearch", "--junitxml=%s" % junit_xml, "--log-level=DEBUG", "--cache-clear", @@ -106,14 +106,14 @@ def run_all(argv=None): ignores = [] # Python 3.6+ is required for async if sys.version_info < (3, 6): - ignores.append("test_elasticsearch/test_async/") + ignores.append("test_opensearch/test_async/") # GitHub Actions, run non-server tests if "GITHUB_ACTION" in environ: ignores.extend( [ - "test_elasticsearch/test_server/", - "test_elasticsearch/test_async/test_server/", + "test_opensearch/test_server/", + "test_opensearch/test_async/test_server/", ] ) if ignores: diff --git a/test_elasticsearch/test_async/__init__.py b/test_opensearch/test_async/__init__.py similarity index 100% rename from test_elasticsearch/test_async/__init__.py rename to test_opensearch/test_async/__init__.py diff --git a/test_elasticsearch/test_async/test_connection.py b/test_opensearch/test_async/test_connection.py similarity index 98% rename from test_elasticsearch/test_async/test_connection.py rename to test_opensearch/test_async/test_connection.py index 6ebd95f4..248fd128 100644 --- a/test_elasticsearch/test_async/test_connection.py +++ b/test_opensearch/test_async/test_connection.py @@ -37,9 +37,9 @@ import pytest from mock import patch from multidict import CIMultiDict -from elasticsearch import AIOHttpConnection, __versionstr__ -from elasticsearch.compat import reraise_exceptions -from elasticsearch.exceptions import ConnectionError +from opensearch import AIOHttpConnection, __versionstr__ +from opensearch.compat import reraise_exceptions +from opensearch.exceptions import ConnectionError pytestmark = pytest.mark.asyncio @@ -213,7 +213,7 @@ class TestAIOHttpConnection: def test_default_user_agent(self): con = AIOHttpConnection() - assert con._get_default_user_agent() == "elasticsearch-py/%s (Python %s)" % ( + assert con._get_default_user_agent() == "opensearch-py/%s (Python %s)" % ( __versionstr__, python_version(), ) @@ -312,7 +312,7 @@ class TestAIOHttpConnection: == str(w[0].message) ) - @patch("elasticsearch.connection.base.logger") + @patch("opensearch.connection.base.logger") async def test_uncompressed_body_logged(self, logger): con = await self._get_mock_connection(connection_params={"http_compress": True}) await con.perform_request("GET", "/", body=b'{"example": "body"}') diff --git a/test_elasticsearch/test_async/test_server/__init__.py b/test_opensearch/test_async/test_server/__init__.py similarity index 100% rename from test_elasticsearch/test_async/test_server/__init__.py rename to test_opensearch/test_async/test_server/__init__.py diff --git a/test_elasticsearch/test_async/test_server/conftest.py b/test_opensearch/test_async/test_server/conftest.py similarity index 83% rename from test_elasticsearch/test_async/test_server/conftest.py rename to test_opensearch/test_async/test_server/conftest.py index e94bec5b..4390c937 100644 --- a/test_elasticsearch/test_async/test_server/conftest.py +++ b/test_opensearch/test_async/test_server/conftest.py @@ -28,8 +28,8 @@ import asyncio import pytest -import elasticsearch -from elasticsearch.helpers.test import CA_CERTS, ELASTICSEARCH_URL +import opensearch +from opensearch.helpers.test import CA_CERTS, OPENSEARCH_URL from ...utils import wipe_cluster @@ -40,11 +40,11 @@ pytestmark = pytest.mark.asyncio async def async_client(): client = None try: - if not hasattr(elasticsearch, "AsyncElasticsearch"): - pytest.skip("test requires 'AsyncElasticsearch'") + if not hasattr(opensearch, "AsyncOpenSearch"): + pytest.skip("test requires 'AsyncOpenSearch'") kw = {"timeout": 3, "ca_certs": CA_CERTS} - client = elasticsearch.AsyncElasticsearch(ELASTICSEARCH_URL, **kw) + client = opensearch.AsyncOpenSearch(OPENSEARCH_URL, **kw) # wait for yellow status for _ in range(100): @@ -55,7 +55,7 @@ async def async_client(): await asyncio.sleep(0.1) else: # timeout - pytest.skip("Elasticsearch failed to start.") + pytest.skip("OpenSearch failed to start.") yield client diff --git a/test_elasticsearch/test_async/test_server/test_clients.py b/test_opensearch/test_async/test_server/test_clients.py similarity index 97% rename from test_elasticsearch/test_async/test_server/test_clients.py rename to test_opensearch/test_async/test_server/test_clients.py index a518923d..2efffd5a 100644 --- a/test_elasticsearch/test_async/test_server/test_clients.py +++ b/test_opensearch/test_async/test_server/test_clients.py @@ -58,7 +58,7 @@ class TestYarlMissing: self, async_client, monkeypatch ): # This is a defensive test case for if aiohttp suddenly stops using yarl. - from elasticsearch._async import http_aiohttp + from opensearch._async import http_aiohttp monkeypatch.setattr(http_aiohttp, "yarl", False) diff --git a/test_elasticsearch/test_async/test_server/test_helpers.py b/test_opensearch/test_async/test_server/test_helpers.py similarity index 99% rename from test_elasticsearch/test_async/test_server/test_helpers.py rename to test_opensearch/test_async/test_server/test_helpers.py index 0c7cb473..81b6960c 100644 --- a/test_elasticsearch/test_async/test_server/test_helpers.py +++ b/test_opensearch/test_async/test_server/test_helpers.py @@ -24,8 +24,8 @@ # specific language governing permissions and limitations # under the License. -# Licensed to Elasticsearch B.V under one or more agreements. -# Elasticsearch B.V licenses this file to you under the Apache 2.0 License. +# Licensed to Elasticsearch B.V.under one or more agreements. +# Elasticsearch B.V.licenses this file to you under the Apache 2.0 License. # See the LICENSE file in the project root for more information import asyncio @@ -33,8 +33,8 @@ import asyncio import pytest from mock import MagicMock, patch -from elasticsearch import TransportError, helpers -from elasticsearch.helpers import ScanError +from opensearch import TransportError, helpers +from opensearch.helpers import ScanError pytestmark = pytest.mark.asyncio @@ -582,7 +582,7 @@ class TestScan(object): scroll_mock.assert_not_called() clear_mock.assert_not_called() - @patch("elasticsearch._async.helpers.logger") + @patch("opensearch._async.helpers.logger") async def test_logger(self, logger_mock, async_client, scan_teardown): bulk = [] for x in range(4): diff --git a/test_elasticsearch/test_async/test_server/test_rest_api_spec.py b/test_opensearch/test_async/test_server/test_rest_api_spec.py similarity index 97% rename from test_elasticsearch/test_async/test_server/test_rest_api_spec.py rename to test_opensearch/test_async/test_server/test_rest_api_spec.py index f1dec77a..c3143089 100644 --- a/test_elasticsearch/test_async/test_server/test_rest_api_spec.py +++ b/test_opensearch/test_async/test_server/test_rest_api_spec.py @@ -26,7 +26,7 @@ """ Dynamically generated set of TestCases based on set of yaml files decribing -some integration tests. These files are shared among all official Elasticsearch +some integration tests. These files are shared among all official OpenSearch clients. """ import inspect @@ -34,8 +34,8 @@ import warnings import pytest -from elasticsearch import ElasticsearchWarning -from elasticsearch.helpers.test import _get_version +from opensearch import OpenSearchWarning +from opensearch.helpers.test import _get_version from ...test_server.test_rest_api_spec import ( IMPLEMENTED_FEATURES, @@ -152,7 +152,7 @@ class AsyncYamlRunner(YamlRunner): for k in args: args[k] = self._resolve(args[k]) - warnings.simplefilter("always", category=ElasticsearchWarning) + warnings.simplefilter("always", category=OpenSearchWarning) with warnings.catch_warnings(record=True) as caught_warnings: try: self.last_response = await api(**args) @@ -170,7 +170,7 @@ class AsyncYamlRunner(YamlRunner): caught_warnings = [ str(w.message) for w in caught_warnings - if w.category == ElasticsearchWarning + if w.category == OpenSearchWarning and str(w.message) not in allowed_warnings ] diff --git a/test_elasticsearch/test_async/test_transport.py b/test_opensearch/test_async/test_transport.py similarity index 97% rename from test_elasticsearch/test_async/test_transport.py rename to test_opensearch/test_async/test_transport.py index 13ddb5b5..1553408a 100644 --- a/test_elasticsearch/test_async/test_transport.py +++ b/test_opensearch/test_async/test_transport.py @@ -34,10 +34,10 @@ import re import pytest from mock import patch -from elasticsearch import AsyncTransport -from elasticsearch.connection import Connection -from elasticsearch.connection_pool import DummyConnectionPool -from elasticsearch.exceptions import ConnectionError, TransportError +from opensearch import AsyncTransport +from opensearch.connection import Connection +from opensearch.connection_pool import DummyConnectionPool +from opensearch.exceptions import ConnectionError, TransportError pytestmark = pytest.mark.asyncio @@ -74,7 +74,7 @@ CLUSTER_NODES = """{ "successful" : 1, "failed" : 0 }, - "cluster_name" : "elasticsearch", + "cluster_name" : "opensearch", "nodes" : { "SRZpKFZdQguhhvifmN6UVA" : { "name" : "SRZpKFZ", @@ -99,7 +99,7 @@ CLUSTER_NODES_7x_PUBLISH_HOST = """{ "successful" : 1, "failed" : 0 }, - "cluster_name" : "elasticsearch", + "cluster_name" : "opensearch", "nodes" : { "SRZpKFZdQguhhvifmN6UVA" : { "name" : "SRZpKFZ", @@ -416,7 +416,7 @@ class TestTransport: assert 1 == len(t.connection_pool.connections) assert "http://1.1.1.1:123" == t.get_connection().host - @patch("elasticsearch._async.transport.AsyncTransport.sniff_hosts") + @patch("opensearch._async.transport.AsyncTransport.sniff_hosts") async def test_sniff_on_fail_failing_does_not_prevent_retires(self, sniff_hosts): sniff_hosts.side_effect = [TransportError("sniff failed")] t = AsyncTransport( @@ -472,7 +472,7 @@ class TestTransport: "port": 123, } - @patch("elasticsearch._async.transport.AsyncTransport.sniff_hosts") + @patch("opensearch._async.transport.AsyncTransport.sniff_hosts") async def test_sniffing_disabled_on_cloud_instances(self, sniff_hosts): t = AsyncTransport( [{}], diff --git a/test_elasticsearch/test_cases.py b/test_opensearch/test_cases.py similarity index 91% rename from test_elasticsearch/test_cases.py rename to test_opensearch/test_cases.py index 12dbce08..ebbb04fc 100644 --- a/test_elasticsearch/test_cases.py +++ b/test_opensearch/test_cases.py @@ -28,7 +28,7 @@ from collections import defaultdict from unittest import SkipTest # noqa: F401 from unittest import TestCase -from elasticsearch import Elasticsearch +from opensearch import OpenSearch class DummyTransport(object): @@ -47,10 +47,10 @@ class DummyTransport(object): return resp -class ElasticsearchTestCase(TestCase): +class OpenSearchTestCase(TestCase): def setUp(self): - super(ElasticsearchTestCase, self).setUp() - self.client = Elasticsearch(transport_class=DummyTransport) + super(OpenSearchTestCase, self).setUp() + self.client = OpenSearch(transport_class=DummyTransport) def assert_call_count_equals(self, count): self.assertEqual(count, self.client.transport.call_count) @@ -62,7 +62,7 @@ class ElasticsearchTestCase(TestCase): return calls -class TestElasticsearchTestCase(ElasticsearchTestCase): +class TestOpenSearchTestCase(OpenSearchTestCase): def test_our_transport_used(self): self.assertIsInstance(self.client.transport, DummyTransport) diff --git a/test_elasticsearch/test_client/__init__.py b/test_opensearch/test_client/__init__.py similarity index 92% rename from test_elasticsearch/test_client/__init__.py rename to test_opensearch/test_client/__init__.py index aafe4d49..19d21881 100644 --- a/test_elasticsearch/test_client/__init__.py +++ b/test_opensearch/test_client/__init__.py @@ -28,9 +28,9 @@ from __future__ import unicode_literals import warnings -from elasticsearch.client import Elasticsearch, _normalize_hosts +from opensearch.client import OpenSearch, _normalize_hosts -from ..test_cases import ElasticsearchTestCase, TestCase +from ..test_cases import OpenSearchTestCase, TestCase class TestNormalizeHosts(TestCase): @@ -76,7 +76,7 @@ class TestNormalizeHosts(TestCase): self.assertEqual([{"host": "elastic.co"}], _normalize_hosts("elastic.co")) -class TestClient(ElasticsearchTestCase): +class TestClient(OpenSearchTestCase): def test_request_timeout_is_passed_through_unescaped(self): self.client.ping(request_timeout=0.1) calls = self.assert_url_called("HEAD", "/") @@ -112,20 +112,20 @@ class TestClient(ElasticsearchTestCase): self.assertEqual([({"from": "10"}, {}, None)], calls) def test_repr_contains_hosts(self): - self.assertEqual("", repr(self.client)) + self.assertEqual("", repr(self.client)) def test_repr_subclass(self): - class OtherElasticsearch(Elasticsearch): + class OtherOpenSearch(OpenSearch): pass - self.assertEqual("", repr(OtherElasticsearch())) + self.assertEqual("", repr(OtherOpenSearch())) def test_repr_contains_hosts_passed_in(self): - self.assertIn("es.org", repr(Elasticsearch(["es.org:123"]))) + self.assertIn("es.org", repr(OpenSearch(["es.org:123"]))) def test_repr_truncates_host_to_5(self): hosts = [{"host": "es" + str(i)} for i in range(10)] - es = Elasticsearch(hosts) + es = OpenSearch(hosts) self.assertNotIn("es5", repr(es)) self.assertIn("...", repr(es)) diff --git a/test_elasticsearch/test_client/test_cluster.py b/test_opensearch/test_client/test_cluster.py similarity index 95% rename from test_elasticsearch/test_client/test_cluster.py rename to test_opensearch/test_client/test_cluster.py index 13028e6c..1644b960 100644 --- a/test_elasticsearch/test_client/test_cluster.py +++ b/test_opensearch/test_client/test_cluster.py @@ -24,10 +24,10 @@ # specific language governing permissions and limitations # under the License. -from test_elasticsearch.test_cases import ElasticsearchTestCase +from test_opensearch.test_cases import OpenSearchTestCase -class TestCluster(ElasticsearchTestCase): +class TestCluster(OpenSearchTestCase): def test_stats_without_node_id(self): self.client.cluster.stats() self.assert_url_called("GET", "/_cluster/stats") diff --git a/test_elasticsearch/test_client/test_indices.py b/test_opensearch/test_client/test_indices.py similarity index 95% rename from test_elasticsearch/test_client/test_indices.py rename to test_opensearch/test_client/test_indices.py index 61430e8b..ec914251 100644 --- a/test_elasticsearch/test_client/test_indices.py +++ b/test_opensearch/test_client/test_indices.py @@ -24,10 +24,10 @@ # specific language governing permissions and limitations # under the License. -from test_elasticsearch.test_cases import ElasticsearchTestCase +from test_opensearch.test_cases import OpenSearchTestCase -class TestIndices(ElasticsearchTestCase): +class TestIndices(OpenSearchTestCase): def test_create_one_index(self): self.client.indices.create("test-index") self.assert_url_called("PUT", "/test-index") diff --git a/test_elasticsearch/test_client/test_overrides.py b/test_opensearch/test_client/test_overrides.py similarity index 98% rename from test_elasticsearch/test_client/test_overrides.py rename to test_opensearch/test_client/test_overrides.py index f6ba17a9..e777ef20 100644 --- a/test_elasticsearch/test_client/test_overrides.py +++ b/test_opensearch/test_client/test_overrides.py @@ -27,10 +27,10 @@ import pytest -from test_elasticsearch.test_cases import ElasticsearchTestCase +from test_opensearch.test_cases import OpenSearchTestCase -class TestOverriddenUrlTargets(ElasticsearchTestCase): +class TestOverriddenUrlTargets(OpenSearchTestCase): def test_create(self): self.client.create(index="test-index", id="test-id", body={}) self.assert_url_called("PUT", "/test-index/_create/test-id") diff --git a/test_elasticsearch/test_client/test_utils.py b/test_opensearch/test_client/test_utils.py similarity index 98% rename from test_elasticsearch/test_client/test_utils.py rename to test_opensearch/test_client/test_utils.py index 2b93ff03..d3ab825a 100644 --- a/test_elasticsearch/test_client/test_utils.py +++ b/test_opensearch/test_client/test_utils.py @@ -27,8 +27,8 @@ from __future__ import unicode_literals -from elasticsearch.client.utils import _bulk_body, _escape, _make_path, query_params -from elasticsearch.compat import PY2 +from opensearch.client.utils import _bulk_body, _escape, _make_path, query_params +from opensearch.compat import PY2 from ..test_cases import SkipTest, TestCase diff --git a/test_elasticsearch/test_connection.py b/test_opensearch/test_connection.py similarity index 96% rename from test_elasticsearch/test_connection.py rename to test_opensearch/test_connection.py index 1dc1a7ac..a367fca9 100644 --- a/test_elasticsearch/test_connection.py +++ b/test_opensearch/test_connection.py @@ -40,14 +40,14 @@ from mock import Mock, patch from requests.auth import AuthBase from urllib3._collections import HTTPHeaderDict -from elasticsearch import __versionstr__ -from elasticsearch.compat import reraise_exceptions -from elasticsearch.connection import ( +from opensearch import __versionstr__ +from opensearch.compat import reraise_exceptions +from opensearch.connection import ( Connection, RequestsHttpConnection, Urllib3HttpConnection, ) -from elasticsearch.exceptions import ( +from opensearch.exceptions import ( ConflictError, ConnectionError, NotFoundError, @@ -133,16 +133,16 @@ class TestBaseConnection(TestCase): con = Connection() with warnings.catch_warnings(record=True) as warn: - con._raise_warnings(['299 Elasticsearch-7.6.1-aa751 "this is deprecated"']) + con._raise_warnings(['299 OpenSearch-7.6.1-aa751 "this is deprecated"']) self.assertEqual([str(w.message) for w in warn], ["this is deprecated"]) with warnings.catch_warnings(record=True) as warn: con._raise_warnings( [ - '299 Elasticsearch-7.6.1-aa751 "this is also deprecated"', - '299 Elasticsearch-7.6.1-aa751 "this is also deprecated"', - '299 Elasticsearch-7.6.1-aa751 "guess what? deprecated"', + '299 OpenSearch-7.6.1-aa751 "this is also deprecated"', + '299 OpenSearch-7.6.1-aa751 "this is also deprecated"', + '299 OpenSearch-7.6.1-aa751 "guess what? deprecated"', ] ) @@ -156,8 +156,8 @@ class TestBaseConnection(TestCase): with warnings.catch_warnings(record=True) as warn: con._raise_warnings( [ - '299 Elasticsearch-7.6.1-aa751 "warning",' - '299 Elasticsearch-7.6.1-aa751 "folded"', + '299 OpenSearch-7.6.1-aa751 "warning",' + '299 OpenSearch-7.6.1-aa751 "folded"', ] ) @@ -199,7 +199,7 @@ class TestBaseConnection(TestCase): conn = Connection() assert ( conn.headers["accept"] - == "application/vnd.elasticsearch+json;compatible-with=7" + == "application/vnd.opensearch+json;compatible-with=7" ) finally: os.environ.pop("ELASTIC_CLIENT_APIVERSIONING") @@ -354,7 +354,7 @@ class TestUrllib3Connection(TestCase): con = Urllib3HttpConnection() self.assertEqual( con._get_default_user_agent(), - "elasticsearch-py/%s (Python %s)" % (__versionstr__, python_version()), + "opensearch-py/%s (Python %s)" % (__versionstr__, python_version()), ) def test_timeout_set(self): @@ -460,7 +460,7 @@ class TestUrllib3Connection(TestCase): str(w[0].message), ) - @patch("elasticsearch.connection.base.logger") + @patch("opensearch.connection.base.logger") def test_uncompressed_body_logged(self, logger): con = self._get_mock_connection(connection_params={"http_compress": True}) con.perform_request("GET", "/", body=b'{"example": "body"}') @@ -724,9 +724,9 @@ class TestRequestsConnection(TestCase): self.assertEqual(("username", "secret"), con.session.auth) def test_repr(self): - con = self._get_mock_connection({"host": "elasticsearch.com", "port": 443}) + con = self._get_mock_connection({"host": "opensearch.com", "port": 443}) self.assertEqual( - "", repr(con) + "", repr(con) ) def test_conflict_error_is_returned_on_409(self): @@ -741,14 +741,14 @@ class TestRequestsConnection(TestCase): con = self._get_mock_connection(status_code=400) self.assertRaises(RequestError, con.perform_request, "GET", "/", {}, "") - @patch("elasticsearch.connection.base.logger") + @patch("opensearch.connection.base.logger") def test_head_with_404_doesnt_get_logged(self, logger): con = self._get_mock_connection(status_code=404) self.assertRaises(NotFoundError, con.perform_request, "HEAD", "/", {}, "") self.assertEqual(0, logger.warning.call_count) - @patch("elasticsearch.connection.base.tracer") - @patch("elasticsearch.connection.base.logger") + @patch("opensearch.connection.base.tracer") + @patch("opensearch.connection.base.logger") def test_failed_request_logs_and_traces(self, logger, tracer): con = self._get_mock_connection( response_body=b'{"answer": 42}', status_code=500 @@ -775,8 +775,8 @@ class TestRequestsConnection(TestCase): ) ) - @patch("elasticsearch.connection.base.tracer") - @patch("elasticsearch.connection.base.logger") + @patch("opensearch.connection.base.tracer") + @patch("opensearch.connection.base.logger") def test_success_logs_and_traces(self, logger, tracer): con = self._get_mock_connection(response_body=b"""{"answer": "that's it!"}""") status, headers, data = con.perform_request( @@ -815,7 +815,7 @@ class TestRequestsConnection(TestCase): self.assertEqual('> {"question": "what\'s that?"}', req[0][0] % req[0][1:]) self.assertEqual('< {"answer": "that\'s it!"}', resp[0][0] % resp[0][1:]) - @patch("elasticsearch.connection.base.logger") + @patch("opensearch.connection.base.logger") def test_uncompressed_body_logged(self, logger): con = self._get_mock_connection(connection_params={"http_compress": True}) con.perform_request("GET", "/", body=b'{"example": "body"}') @@ -870,7 +870,7 @@ class TestRequestsConnection(TestCase): self.assertEqual(request.headers["authorization"], "Basic dXNlcm5hbWU6c2VjcmV0") - @patch("elasticsearch.connection.base.tracer") + @patch("opensearch.connection.base.tracer") def test_url_prefix(self, tracer): con = self._get_mock_connection({"url_prefix": "/some-prefix/"}) request = self._get_request( diff --git a/test_elasticsearch/test_connection_pool.py b/test_opensearch/test_connection_pool.py similarity index 97% rename from test_elasticsearch/test_connection_pool.py rename to test_opensearch/test_connection_pool.py index e3330f5d..65a54052 100644 --- a/test_elasticsearch/test_connection_pool.py +++ b/test_opensearch/test_connection_pool.py @@ -26,13 +26,13 @@ import time -from elasticsearch.connection import Connection -from elasticsearch.connection_pool import ( +from opensearch.connection import Connection +from opensearch.connection_pool import ( ConnectionPool, DummyConnectionPool, RoundRobinSelector, ) -from elasticsearch.exceptions import ImproperlyConfigured +from opensearch.exceptions import ImproperlyConfigured from .test_cases import TestCase diff --git a/test_elasticsearch/test_exceptions.py b/test_opensearch/test_exceptions.py similarity index 97% rename from test_elasticsearch/test_exceptions.py rename to test_opensearch/test_exceptions.py index 2cb17777..061855c8 100644 --- a/test_elasticsearch/test_exceptions.py +++ b/test_opensearch/test_exceptions.py @@ -24,7 +24,7 @@ # specific language governing permissions and limitations # under the License. -from elasticsearch.exceptions import TransportError +from opensearch.exceptions import TransportError from .test_cases import TestCase diff --git a/test_elasticsearch/test_helpers.py b/test_opensearch/test_helpers.py similarity index 94% rename from test_elasticsearch/test_helpers.py rename to test_opensearch/test_helpers.py index 3ade2b43..80463853 100644 --- a/test_elasticsearch/test_helpers.py +++ b/test_opensearch/test_helpers.py @@ -31,9 +31,9 @@ import time import mock import pytest -from elasticsearch import Elasticsearch, helpers -from elasticsearch.helpers import actions -from elasticsearch.serializer import JSONSerializer +from opensearch import OpenSearch, helpers +from opensearch.helpers import actions +from opensearch.serializer import JSONSerializer from .test_cases import TestCase @@ -57,18 +57,18 @@ mock_process_bulk_chunk.call_count = 0 class TestParallelBulk(TestCase): @mock.patch( - "elasticsearch.helpers.actions._process_bulk_chunk", + "opensearch.helpers.actions._process_bulk_chunk", side_effect=mock_process_bulk_chunk, ) def test_all_chunks_sent(self, _process_bulk_chunk): actions = ({"x": i} for i in range(100)) - list(helpers.parallel_bulk(Elasticsearch(), actions, chunk_size=2)) + list(helpers.parallel_bulk(OpenSearch(), actions, chunk_size=2)) self.assertEqual(50, mock_process_bulk_chunk.call_count) @pytest.mark.skip @mock.patch( - "elasticsearch.helpers.actions._process_bulk_chunk", + "opensearch.helpers.actions._process_bulk_chunk", # make sure we spend some time in the thread side_effect=lambda *a: [ (True, time.sleep(0.001) or threading.current_thread().ident) @@ -77,9 +77,7 @@ class TestParallelBulk(TestCase): def test_chunk_sent_from_different_threads(self, _process_bulk_chunk): actions = ({"x": i} for i in range(100)) results = list( - helpers.parallel_bulk( - Elasticsearch(), actions, thread_count=10, chunk_size=2 - ) + helpers.parallel_bulk(OpenSearch(), actions, thread_count=10, chunk_size=2) ) self.assertTrue(len(set([r[1] for r in results])) > 1) diff --git a/test_elasticsearch/test_serializer.py b/test_opensearch/test_serializer.py similarity index 94% rename from test_elasticsearch/test_serializer.py rename to test_opensearch/test_serializer.py index b38dc8df..b92ab3f3 100644 --- a/test_elasticsearch/test_serializer.py +++ b/test_opensearch/test_serializer.py @@ -36,8 +36,8 @@ try: except ImportError: np = pd = None -from elasticsearch.exceptions import ImproperlyConfigured, SerializationError -from elasticsearch.serializer import ( +from opensearch.exceptions import ImproperlyConfigured, SerializationError +from opensearch.serializer import ( DEFAULT_SERIALIZERS, Deserializer, JSONSerializer, @@ -128,7 +128,7 @@ class TestJSONSerializer(TestCase): '{"d":[0,0,0,0,0]}', JSONSerializer().dumps({"d": np.zeros((5,), dtype=np.uint8)}), ) - # This isn't useful for Elasticsearch, just want to make sure it works. + # This isn't useful for OpenSearch, just want to make sure it works. self.assertEqual( '{"d":[[0,0],[0,0]]}', JSONSerializer().dumps({"d": np.zeros((2, 2), dtype=np.uint8)}), @@ -228,10 +228,10 @@ class TestDeserializer(TestCase): def test_deserialize_compatibility_header(self): for content_type in ( - "application/vnd.elasticsearch+json;compatible-with=7", - "application/vnd.elasticsearch+json; compatible-with=7", - "application/vnd.elasticsearch+json;compatible-with=8", - "application/vnd.elasticsearch+json; compatible-with=8", + "application/vnd.opensearch+json;compatible-with=7", + "application/vnd.opensearch+json; compatible-with=7", + "application/vnd.opensearch+json;compatible-with=8", + "application/vnd.opensearch+json; compatible-with=8", ): self.assertEqual( {"some": "data"}, self.de.loads('{"some":"data"}', content_type) diff --git a/test_elasticsearch/test_server/__init__.py b/test_opensearch/test_server/__init__.py similarity index 88% rename from test_elasticsearch/test_server/__init__.py rename to test_opensearch/test_server/__init__.py index 98bddf20..67c82e19 100644 --- a/test_elasticsearch/test_server/__init__.py +++ b/test_opensearch/test_server/__init__.py @@ -26,8 +26,8 @@ from unittest import SkipTest -from elasticsearch.helpers import test -from elasticsearch.helpers.test import ElasticsearchTestCase as BaseTestCase +from opensearch.helpers import test +from opensearch.helpers.test import OpenSearchTestCase as BaseTestCase client = None @@ -41,7 +41,7 @@ def get_client(**kwargs): # try and locate manual override in the local environment try: - from test_elasticsearch.local import get_client as local_get_client + from test_opensearch.local import get_client as local_get_client new_client = local_get_client(**kwargs) except ImportError: @@ -62,7 +62,7 @@ def setup_module(): get_client() -class ElasticsearchTestCase(BaseTestCase): +class OpenSearchTestCase(BaseTestCase): @staticmethod def _get_client(**kwargs): return get_client(**kwargs) diff --git a/test_elasticsearch/test_server/conftest.py b/test_opensearch/test_server/conftest.py similarity index 83% rename from test_elasticsearch/test_server/conftest.py rename to test_opensearch/test_server/conftest.py index ddf3a9b7..3feabc28 100644 --- a/test_elasticsearch/test_server/conftest.py +++ b/test_opensearch/test_server/conftest.py @@ -29,16 +29,16 @@ import time import pytest -import elasticsearch -from elasticsearch.helpers.test import CA_CERTS, ELASTICSEARCH_URL +import opensearch +from opensearch.helpers.test import CA_CERTS, OPENSEARCH_URL from ..utils import wipe_cluster -# Information about the Elasticsearch instance running, if any +# Information about the OpenSearch instance running, if any # Used for -ELASTICSEARCH_VERSION = "" -ELASTICSEARCH_BUILD_HASH = "" -ELASTICSEARCH_REST_API_TESTS = [] +OPENSEARCH_VERSION = "" +OPENSEARCH_BUILD_HASH = "" +OPENSEARCH_REST_API_TESTS = [] @pytest.fixture(scope="session") @@ -53,7 +53,7 @@ def sync_client_factory(): "headers": {"Authorization": "Basic ZWxhc3RpYzpjaGFuZ2VtZQ=="}, } if "PYTHON_CONNECTION_CLASS" in os.environ: - from elasticsearch import connection + from opensearch import connection kw["connection_class"] = getattr( connection, os.environ["PYTHON_CONNECTION_CLASS"] @@ -61,8 +61,8 @@ def sync_client_factory(): # We do this little dance with the URL to force # Requests to respect 'headers: None' within rest API spec tests. - client = elasticsearch.Elasticsearch( - ELASTICSEARCH_URL.replace("elastic:changeme@", ""), **kw + client = opensearch.OpenSearch( + OPENSEARCH_URL.replace("elastic:changeme@", ""), **kw ) # Wait for the cluster to report a status of 'yellow' @@ -73,7 +73,7 @@ def sync_client_factory(): except ConnectionError: time.sleep(0.1) else: - pytest.skip("Elasticsearch wasn't running at %r" % (ELASTICSEARCH_URL,)) + pytest.skip("OpenSearch wasn't running at %r" % (OPENSEARCH_URL,)) wipe_cluster(client) yield client diff --git a/test_elasticsearch/test_server/test_clients.py b/test_opensearch/test_server/test_clients.py similarity index 93% rename from test_elasticsearch/test_server/test_clients.py rename to test_opensearch/test_server/test_clients.py index 8ec01edf..243c0b8a 100644 --- a/test_elasticsearch/test_server/test_clients.py +++ b/test_opensearch/test_server/test_clients.py @@ -27,15 +27,15 @@ from __future__ import unicode_literals -from . import ElasticsearchTestCase +from . import OpenSearchTestCase -class TestUnicode(ElasticsearchTestCase): +class TestUnicode(OpenSearchTestCase): def test_indices_analyze(self): self.client.indices.analyze(body='{"text": "привет"}') -class TestBulk(ElasticsearchTestCase): +class TestBulk(OpenSearchTestCase): def test_bulk_works_with_string_body(self): docs = '{ "index" : { "_index" : "bulk_test_index", "_id" : "1" } }\n{"answer": 42}' response = self.client.bulk(body=docs) diff --git a/test_elasticsearch/test_server/test_helpers.py b/test_opensearch/test_server/test_helpers.py similarity index 98% rename from test_elasticsearch/test_server/test_helpers.py rename to test_opensearch/test_server/test_helpers.py index 52aae88a..fc960325 100644 --- a/test_elasticsearch/test_server/test_helpers.py +++ b/test_opensearch/test_server/test_helpers.py @@ -26,11 +26,11 @@ from mock import patch -from elasticsearch import TransportError, helpers -from elasticsearch.helpers import ScanError +from opensearch import TransportError, helpers +from opensearch.helpers import ScanError from ..test_cases import SkipTest -from . import ElasticsearchTestCase +from . import OpenSearchTestCase class FailingBulkClient(object): @@ -50,7 +50,7 @@ class FailingBulkClient(object): return self.client.bulk(*args, **kwargs) -class TestStreamingBulk(ElasticsearchTestCase): +class TestStreamingBulk(OpenSearchTestCase): def test_actions_remain_unchanged(self): actions = [{"_id": 1}, {"_id": 2}] for ok, item in helpers.streaming_bulk( @@ -229,7 +229,7 @@ class TestStreamingBulk(ElasticsearchTestCase): self.assertEqual(4, failing_client._called) -class TestBulk(ElasticsearchTestCase): +class TestBulk(OpenSearchTestCase): def test_bulk_works_with_single_item(self): docs = [{"answer": 42, "_id": 1}] success, failed = helpers.bulk( @@ -366,7 +366,7 @@ class TestBulk(ElasticsearchTestCase): self.assertEqual(1, failed) -class TestScan(ElasticsearchTestCase): +class TestScan(OpenSearchTestCase): mock_scroll_responses = [ { "_scroll_id": "dummy_id", @@ -550,7 +550,7 @@ class TestScan(ElasticsearchTestCase): ) self.assertEqual(client_mock.scroll.call_args[1]["sort"], "asc") - @patch("elasticsearch.helpers.actions.logger") + @patch("opensearch.helpers.actions.logger") def test_logger(self, logger_mock): bulk = [] for x in range(4): @@ -641,7 +641,7 @@ class TestScan(ElasticsearchTestCase): self.assertEqual(data, [{"search_data": 1}, {"scroll_data": 42}]) -class TestReindex(ElasticsearchTestCase): +class TestReindex(OpenSearchTestCase): def setup_method(self, _): bulk = [] for x in range(100): @@ -711,7 +711,7 @@ class TestReindex(ElasticsearchTestCase): ) -class TestParentChildReindex(ElasticsearchTestCase): +class TestParentChildReindex(OpenSearchTestCase): def setup_method(self, _): body = { "settings": {"number_of_shards": 1, "number_of_replicas": 0}, diff --git a/test_elasticsearch/test_server/test_rest_api_spec.py b/test_opensearch/test_server/test_rest_api_spec.py similarity index 96% rename from test_elasticsearch/test_server/test_rest_api_spec.py rename to test_opensearch/test_server/test_rest_api_spec.py index 19dcd39c..480f46a3 100644 --- a/test_elasticsearch/test_server/test_rest_api_spec.py +++ b/test_opensearch/test_server/test_rest_api_spec.py @@ -26,7 +26,7 @@ """ Dynamically generated set of TestCases based on set of yaml files describing -some integration tests. These files are shared among all official Elasticsearch +some integration tests. These files are shared among all official OpenSearch clients. """ import io @@ -41,10 +41,10 @@ import pytest import urllib3 import yaml -from elasticsearch import ElasticsearchWarning, TransportError -from elasticsearch.client.utils import _base64_auth_header -from elasticsearch.compat import string_types -from elasticsearch.helpers.test import _get_version +from opensearch import OpenSearchWarning, TransportError +from opensearch.client.utils import _base64_auth_header +from opensearch.compat import string_types +from opensearch.helpers.test import _get_version from . import get_client @@ -235,7 +235,7 @@ class YamlRunner: for k in args: args[k] = self._resolve(args[k]) - warnings.simplefilter("always", category=ElasticsearchWarning) + warnings.simplefilter("always", category=OpenSearchWarning) with warnings.catch_warnings(record=True) as caught_warnings: try: self.last_response = api(**args) @@ -253,7 +253,7 @@ class YamlRunner: caught_warnings = [ str(w.message) for w in caught_warnings - if w.category == ElasticsearchWarning + if w.category == OpenSearchWarning and str(w.message) not in allowed_warnings ] @@ -465,11 +465,11 @@ YAML_TEST_SPECS = [] # Try loading the REST API test specs from the Elastic Artifacts API try: - # Construct the HTTP and Elasticsearch client + # Construct the HTTP and OpenSearch client http = urllib3.PoolManager(retries=10) client = get_client() - # Make a request to Elasticsearch for the build hash, we'll be looking for + # Make a request to OpenSearch for the build hash, we'll be looking for # an artifact with this same hash to download test specs for. client_info = client.info() version_number = client_info["version"]["number"] @@ -487,14 +487,14 @@ try: # hope for the best! builds = resp["version"]["builds"] for build in builds: - if build["projects"]["elasticsearch"]["commit_hash"] == build_hash: + if build["projects"]["opensearch"]["commit_hash"] == build_hash: break else: build = builds[0] # Use the latest # Now we're looking for the 'rest-api-spec--sources.jar' file # to download and extract in-memory. - packages = build["projects"]["elasticsearch"]["packages"] + packages = build["projects"]["opensearch"]["packages"] for package in packages: if re.match(r"rest-resources-zip-.*\.zip", package): package_url = packages[package]["url"] diff --git a/test_elasticsearch/test_transport.py b/test_opensearch/test_transport.py similarity index 97% rename from test_elasticsearch/test_transport.py rename to test_opensearch/test_transport.py index a7c45e4a..21c90ec7 100644 --- a/test_elasticsearch/test_transport.py +++ b/test_opensearch/test_transport.py @@ -33,10 +33,10 @@ import time import pytest from mock import patch -from elasticsearch.connection import Connection -from elasticsearch.connection_pool import DummyConnectionPool -from elasticsearch.exceptions import ConnectionError, TransportError -from elasticsearch.transport import Transport, get_host_info +from opensearch.connection import Connection +from opensearch.connection_pool import DummyConnectionPool +from opensearch.exceptions import ConnectionError, TransportError +from opensearch.transport import Transport, get_host_info from .test_cases import TestCase @@ -62,7 +62,7 @@ CLUSTER_NODES = """{ "successful" : 1, "failed" : 0 }, - "cluster_name" : "elasticsearch", + "cluster_name" : "opensearch", "nodes" : { "SRZpKFZdQguhhvifmN6UVA" : { "name" : "SRZpKFZ", @@ -87,7 +87,7 @@ CLUSTER_NODES_7x_PUBLISH_HOST = """{ "successful" : 1, "failed" : 0 }, - "cluster_name" : "elasticsearch", + "cluster_name" : "opensearch", "nodes" : { "SRZpKFZdQguhhvifmN6UVA" : { "name" : "SRZpKFZ", @@ -383,7 +383,7 @@ class TestTransport(TestCase): self.assertEqual(1, len(t.connection_pool.connections)) self.assertEqual("http://1.1.1.1:123", t.get_connection().host) - @patch("elasticsearch.transport.Transport.sniff_hosts") + @patch("opensearch.transport.Transport.sniff_hosts") def test_sniff_on_fail_failing_does_not_prevent_retires(self, sniff_hosts): sniff_hosts.side_effect = [TransportError("sniff failed")] t = Transport( @@ -434,7 +434,7 @@ class TestTransport(TestCase): {"host": "somehost.tld", "port": 123}, ) - @patch("elasticsearch.transport.Transport.sniff_hosts") + @patch("opensearch.transport.Transport.sniff_hosts") def test_sniffing_disabled_on_cloud_instances(self, sniff_hosts): t = Transport( [{}], diff --git a/test_elasticsearch/test_types/README.md b/test_opensearch/test_types/README.md similarity index 100% rename from test_elasticsearch/test_types/README.md rename to test_opensearch/test_types/README.md diff --git a/test_elasticsearch/test_types/aliased_types.py b/test_opensearch/test_types/aliased_types.py similarity index 97% rename from test_elasticsearch/test_types/aliased_types.py rename to test_opensearch/test_types/aliased_types.py index 9f528d36..252962c1 100644 --- a/test_elasticsearch/test_types/aliased_types.py +++ b/test_opensearch/test_types/aliased_types.py @@ -26,16 +26,16 @@ from typing import Any, AsyncGenerator, Dict, Generator -from elasticsearch7 import ( +from opensearch7 import ( AIOHttpConnection, - AsyncElasticsearch, + AsyncOpenSearch, AsyncTransport, ConnectionPool, - Elasticsearch, + OpenSearch, RequestsHttpConnection, Transport, ) -from elasticsearch7.helpers import ( +from opensearch7.helpers import ( async_bulk, async_reindex, async_scan, @@ -46,7 +46,7 @@ from elasticsearch7.helpers import ( streaming_bulk, ) -es = Elasticsearch( +es = OpenSearch( [{"host": "localhost", "port": 9443}], transport_class=Transport, ) @@ -125,7 +125,7 @@ def reindex_types() -> None: ) -es2 = AsyncElasticsearch( +es2 = AsyncOpenSearch( [{"host": "localhost", "port": 9443}], transport_class=AsyncTransport, ) diff --git a/test_elasticsearch/test_types/async_types.py b/test_opensearch/test_types/async_types.py similarity index 96% rename from test_elasticsearch/test_types/async_types.py rename to test_opensearch/test_types/async_types.py index 8938503e..dee94466 100644 --- a/test_elasticsearch/test_types/async_types.py +++ b/test_opensearch/test_types/async_types.py @@ -26,20 +26,20 @@ from typing import Any, AsyncGenerator, Dict -from elasticsearch import ( +from opensearch import ( AIOHttpConnection, - AsyncElasticsearch, + AsyncOpenSearch, AsyncTransport, ConnectionPool, ) -from elasticsearch.helpers import ( +from opensearch.helpers import ( async_bulk, async_reindex, async_scan, async_streaming_bulk, ) -es = AsyncElasticsearch( +es = AsyncOpenSearch( [{"host": "localhost", "port": 9443}], transport_class=AsyncTransport, ) diff --git a/test_elasticsearch/test_types/sync_types.py b/test_opensearch/test_types/sync_types.py similarity index 93% rename from test_elasticsearch/test_types/sync_types.py rename to test_opensearch/test_types/sync_types.py index 42c43fcb..cfd4c12f 100644 --- a/test_elasticsearch/test_types/sync_types.py +++ b/test_opensearch/test_types/sync_types.py @@ -26,15 +26,10 @@ from typing import Any, Dict, Generator -from elasticsearch import ( - ConnectionPool, - Elasticsearch, - RequestsHttpConnection, - Transport, -) -from elasticsearch.helpers import bulk, reindex, scan, streaming_bulk +from opensearch import ConnectionPool, OpenSearch, RequestsHttpConnection, Transport +from opensearch.helpers import bulk, reindex, scan, streaming_bulk -es = Elasticsearch( +es = OpenSearch( [{"host": "localhost", "port": 9443}], transport_class=Transport, ) diff --git a/test_elasticsearch/test_utils.py b/test_opensearch/test_utils.py similarity index 96% rename from test_elasticsearch/test_utils.py rename to test_opensearch/test_utils.py index cb2ab625..ebdb042c 100644 --- a/test_elasticsearch/test_utils.py +++ b/test_opensearch/test_utils.py @@ -26,7 +26,7 @@ import pytest -from elasticsearch.utils import _client_meta_version +from opensearch.utils import _client_meta_version @pytest.mark.parametrize( diff --git a/test_elasticsearch/utils.py b/test_opensearch/utils.py similarity index 96% rename from test_elasticsearch/utils.py rename to test_opensearch/utils.py index 22cb2ae6..fef7ab8f 100644 --- a/test_elasticsearch/utils.py +++ b/test_opensearch/utils.py @@ -26,7 +26,7 @@ import time -from elasticsearch import Elasticsearch +from opensearch import OpenSearch def wipe_cluster(client): @@ -35,10 +35,10 @@ def wipe_cluster(client): try: # If client is async we need to replace the client # with a synchronous one. - from elasticsearch import AsyncElasticsearch + from opensearch import AsyncOpenSearch - if isinstance(client, AsyncElasticsearch): - client = Elasticsearch(client.transport.hosts, verify_certs=False) + if isinstance(client, AsyncOpenSearch): + client = OpenSearch(client.transport.hosts, verify_certs=False) close_after_wipe = True except ImportError: pass diff --git a/utils/build-dists.py b/utils/build-dists.py index 2d9835a3..8b4a2dfa 100644 --- a/utils/build-dists.py +++ b/utils/build-dists.py @@ -25,7 +25,7 @@ # under the License. """A command line tool for building and verifying releases -Can be used for building both 'elasticsearch' and 'elasticsearchX' dists. +Can be used for building both 'opensearch' and 'elasticsearchX' dists. Only requires 'name' in 'setup.py' and the directory to be changed. """ @@ -70,7 +70,7 @@ def run(*argv, expect_exit_code=0): def test_dist(dist): with set_tmp_dir() as tmp_dir: - dist_name = re.match(r"^(elasticsearch\d*)-", os.path.basename(dist)).group(1) + dist_name = re.match(r"^(opensearch\d*)-", os.path.basename(dist)).group(1) # Build the venv and install the dist run("python", "-m", "venv", os.path.join(tmp_dir, "venv")) @@ -79,13 +79,13 @@ def test_dist(dist): run(venv_python, "-m", "pip", "install", dist) # Test the sync namespaces - run(venv_python, "-c", f"from {dist_name} import Elasticsearch") + run(venv_python, "-c", f"from {dist_name} import OpenSearch") run( venv_python, "-c", f"from {dist_name}.helpers import scan, bulk, streaming_bulk, reindex", ) - run(venv_python, "-c", f"from {dist_name} import Elasticsearch") + run(venv_python, "-c", f"from {dist_name} import OpenSearch") run( venv_python, "-c", @@ -96,7 +96,7 @@ def test_dist(dist): run( venv_python, "-c", - f"from {dist_name} import AsyncElasticsearch", + f"from {dist_name} import AsyncOpenSearch", expect_exit_code=256, ) run( @@ -108,7 +108,7 @@ def test_dist(dist): # Install aiohttp and see that async is now available run(venv_python, "-m", "pip", "install", "aiohttp") - run(venv_python, "-c", f"from {dist_name} import AsyncElasticsearch") + run(venv_python, "-c", f"from {dist_name} import AsyncOpenSearch") run( venv_python, "-c", @@ -117,18 +117,18 @@ def test_dist(dist): # Only need to test 'async_types' for non-aliased package # since 'aliased_types' tests both async and sync. - if dist_name == "elasticsearch": + if dist_name == "opensearch": run( venv_python, "-m", "mypy", "--strict", - os.path.join(base_dir, "test_elasticsearch/test_types/async_types.py"), + os.path.join(base_dir, "test_opensearch/test_types/async_types.py"), ) # Ensure that the namespaces are correct for the dist for suffix in ("", "1", "2", "5", "6", "7", "8", "9", "10"): - distx_name = f"elasticsearch{suffix}" + distx_name = f"opensearch{suffix}" run( venv_python, "-c", @@ -136,15 +136,15 @@ def test_dist(dist): expect_exit_code=256 if distx_name != dist_name else 0, ) - # Check that sync types work for 'elasticsearch' and - # that aliased types work for 'elasticsearchX' - if dist_name == "elasticsearch": + # Check that sync types work for 'opensearch' and + # that aliased types work for 'opensearchX' + if dist_name == "opensearch": run( venv_python, "-m", "mypy", "--strict", - os.path.join(base_dir, "test_elasticsearch/test_types/sync_types.py"), + os.path.join(base_dir, "test_opensearch/test_types/sync_types.py"), ) else: run( @@ -152,9 +152,7 @@ def test_dist(dist): "-m", "mypy", "--strict", - os.path.join( - base_dir, "test_elasticsearch/test_types/aliased_types.py" - ), + os.path.join(base_dir, "test_opensearch/test_types/aliased_types.py"), ) # Uninstall the dist, see that we can't import things anymore @@ -162,17 +160,17 @@ def test_dist(dist): run( venv_python, "-c", - f"from {dist_name} import Elasticsearch", + f"from {dist_name} import OpenSearch", expect_exit_code=256, ) def main(): - run("git", "checkout", "--", "setup.py", "elasticsearch/") + run("git", "checkout", "--", "setup.py", "opensearch/") run("rm", "-rf", "build/", "dist/*", "*.egg-info", ".eggs") # Grab the major version to be used as a suffix. - version_path = os.path.join(base_dir, "elasticsearch/_version.py") + version_path = os.path.join(base_dir, "opensearch/_version.py") with open(version_path) as f: version = re.search( r"^__versionstr__\s+=\s+[\"\']([^\"\']+)[\"\']", f.read(), re.M @@ -230,12 +228,12 @@ def main(): # Rename the module to fit the suffix. shutil.move( - os.path.join(base_dir, "elasticsearch"), - os.path.join(base_dir, "elasticsearch%s" % suffix), + os.path.join(base_dir, "opensearch"), + os.path.join(base_dir, "opensearch%s" % suffix), ) - # Ensure that the version within 'elasticsearch/_version.py' is correct. - version_path = os.path.join(base_dir, f"elasticsearch{suffix}/_version.py") + # Ensure that the version within 'opensearch/_version.py' is correct. + version_path = os.path.join(base_dir, f"opensearch{suffix}/_version.py") with open(version_path) as f: version_data = f.read() version_data = re.sub( @@ -253,11 +251,11 @@ def main(): setup_py = f.read() with open(setup_py_path, "w") as f: f.truncate() - assert 'package_name = "elasticsearch"' in setup_py + assert 'package_name = "opensearch"' in setup_py f.write( setup_py.replace( - 'package_name = "elasticsearch"', - 'package_name = "elasticsearch%s"' % suffix, + 'package_name = "opensearch"', + 'package_name = "opensearch%s"' % suffix, ) ) @@ -265,9 +263,9 @@ def main(): run("python", "setup.py", "sdist", "bdist_wheel") # Clean up everything. - run("git", "checkout", "--", "setup.py", "elasticsearch/") + run("git", "checkout", "--", "setup.py", "opensearch/") if suffix: - run("rm", "-rf", "elasticsearch%s/" % suffix) + run("rm", "-rf", "opensearch%s/" % suffix) # Test everything that got created dists = os.listdir(os.path.join(base_dir, "dist")) diff --git a/utils/generate-api.py b/utils/generate-api.py index 558d5b4c..32f3d090 100644 --- a/utils/generate-api.py +++ b/utils/generate-api.py @@ -144,7 +144,7 @@ class Module: def filepath(self): return ( CODE_ROOT - / f"elasticsearch/_async/client/{self.namespace}.py{'i' if self.is_pyi else ''}" + / f"opensearch/_async/client/{self.namespace}.py{'i' if self.is_pyi else ''}" ) @@ -184,8 +184,8 @@ class API: # Try setting doc refs like 'current' and 'master' to our branches ref. if BRANCH_NAME is not None: revised_url = re.sub( - "/elasticsearch/reference/[^/]+/", - f"/elasticsearch/reference/{BRANCH_NAME}/", + "/opensearch/reference/[^/]+/", + f"/opensearch/reference/{BRANCH_NAME}/", self.doc_url, ) if is_valid_url(revised_url): @@ -338,9 +338,9 @@ def download_artifact(version): resp = http.request( "GET", f"https://artifacts-api.elastic.co/v1/versions/{version}" ) - packages = json.loads(resp.data)["version"]["builds"][0]["projects"][ - "elasticsearch" - ]["packages"] + packages = json.loads(resp.data)["version"]["builds"][0]["projects"]["opensearch"][ + "packages" + ] for package in packages: if re.match(r"^rest-resources-zip-.*\.zip$", package): zip_url = packages[package]["url"] @@ -404,20 +404,20 @@ def dump_modules(modules): additional_replacements = { # We want to rewrite to 'Transport' instead of 'SyncTransport', etc "AsyncTransport": "Transport", - "AsyncElasticsearch": "Elasticsearch", + "AsyncOpenSearch": "OpenSearch", # We don't want to rewrite this class "AsyncSearchClient": "AsyncSearchClient", } rules = [ unasync.Rule( - fromdir="/elasticsearch/_async/client/", - todir="/elasticsearch/client/", + fromdir="/opensearch/_async/client/", + todir="/opensearch/client/", additional_replacements=additional_replacements, ), ] filepaths = [] - for root, _, filenames in os.walk(CODE_ROOT / "elasticsearch/_async"): + for root, _, filenames in os.walk(CODE_ROOT / "opensearch/_async"): for filename in filenames: if ( filename.rpartition(".")[-1] @@ -430,7 +430,7 @@ def dump_modules(modules): filepaths.append(os.path.join(root, filename)) unasync.unasync_files(filepaths, rules) - blacken(CODE_ROOT / "elasticsearch") + blacken(CODE_ROOT / "opensearch") if __name__ == "__main__":