Rename Elasticsearch -> OpenSearch
Signed-off-by: Rushi Agrawal <rushi.agr@gmail.com>
This commit is contained in:
@@ -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 \
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
+5
-5
@@ -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 <target> <params>
|
||||
@@ -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
|
||||
|
||||
@@ -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 \
|
||||
+12
-12
@@ -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
|
||||
|
||||
+3
-4
@@ -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
|
||||
|
||||
+2
-2
@@ -5,5 +5,5 @@ omit =
|
||||
*/lib_pypy/*
|
||||
*/site-packages/*
|
||||
*.egg/*
|
||||
test_elasticsearch/*
|
||||
elasticsearch/connection/esthrift/*
|
||||
test_opensearch/*
|
||||
opensearch/connection/esthrift/*
|
||||
|
||||
+3
-3
@@ -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
|
||||
|
||||
+2
-2
@@ -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]
|
||||
|
||||
@@ -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
|
||||
|
||||
+7
-7
@@ -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()
|
||||
|
||||
@@ -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
|
||||
@@ -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):
|
||||
@@ -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
|
||||
<https://github.com/elastic/elasticsearch-py/blob/master/elasticsearch/serializer.py#L24>`_
|
||||
<https://github.com/opensearch-project/opensearch-py/blob/master/opensearch/serializer.py#L24>`_
|
||||
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"):
|
||||
@@ -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 #
|
||||
@@ -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.
|
||||
@@ -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: ...
|
||||
@@ -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(
|
||||
@@ -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]] = ...,
|
||||
@@ -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
|
||||
@@ -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
|
||||
"""
|
||||
@@ -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
|
||||
<https://github.com/elastic/elasticsearch-py/blob/master/elasticsearch/serializer.py#L24>`_
|
||||
<https://github.com/opensearch-project/opensearch-py/blob/master/opensearch/serializer.py#L24>`_
|
||||
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"):
|
||||
@@ -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 #
|
||||
@@ -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.
|
||||
@@ -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:
|
||||
@@ -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: ...
|
||||
@@ -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):
|
||||
"""
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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]
|
||||
@@ -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)
|
||||
@@ -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]] = ...,
|
||||
@@ -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
|
||||
@@ -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: ...
|
||||
@@ -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()
|
||||
@@ -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: ...
|
||||
@@ -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]
|
||||
@@ -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
|
||||
"""
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user