Rename module to opensearchpy
To avoid conflict with an existing package by name 'opensearch' being present Signed-off-by: Rushi Agrawal <[email protected]>
This commit is contained in:
@@ -32,7 +32,7 @@ pip install git+https://github.com/opensearch-project/opensearch-py.git
|
|||||||
Then import it like any other module:
|
Then import it like any other module:
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from opensearch import OpenSearch
|
from opensearchpy import OpenSearch
|
||||||
```
|
```
|
||||||
|
|
||||||
If you prefer to add the client manually or just want to examine the source code, see [opensearch-py on GitHub](https://github.com/opensearch-project/opensearch-py).
|
If you prefer to add the client manually or just want to examine the source code, see [opensearch-py on GitHub](https://github.com/opensearch-project/opensearch-py).
|
||||||
@@ -41,7 +41,7 @@ If you prefer to add the client manually or just want to examine the source code
|
|||||||
## Sample code
|
## Sample code
|
||||||
|
|
||||||
```python
|
```python
|
||||||
from opensearch import OpenSearch
|
from opensearchpy import OpenSearch
|
||||||
|
|
||||||
host = 'localhost'
|
host = 'localhost'
|
||||||
port = 9200
|
port = 9200
|
||||||
|
|||||||
+7
-7
@@ -29,8 +29,8 @@ import nox
|
|||||||
SOURCE_FILES = (
|
SOURCE_FILES = (
|
||||||
"setup.py",
|
"setup.py",
|
||||||
"noxfile.py",
|
"noxfile.py",
|
||||||
"opensearch/",
|
"opensearchpy/",
|
||||||
"test_opensearch/",
|
"test_opensearchpy/",
|
||||||
"utils/",
|
"utils/",
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -68,15 +68,15 @@ def lint(session):
|
|||||||
|
|
||||||
# Run mypy on the package and then the type examples separately for
|
# Run mypy on the package and then the type examples separately for
|
||||||
# the two different mypy use-cases, ourselves and our users.
|
# the two different mypy use-cases, ourselves and our users.
|
||||||
session.run("mypy", "--strict", "opensearch/")
|
session.run("mypy", "--strict", "opensearchpy/")
|
||||||
session.run("mypy", "--strict", "test_opensearch/test_types/sync_types.py")
|
session.run("mypy", "--strict", "test_opensearchpy/test_types/sync_types.py")
|
||||||
session.run("mypy", "--strict", "test_opensearch/test_types/async_types.py")
|
session.run("mypy", "--strict", "test_opensearchpy/test_types/async_types.py")
|
||||||
|
|
||||||
# Make sure we don't require aiohttp to be installed for users to
|
# Make sure we don't require aiohttp to be installed for users to
|
||||||
# receive type hint information from mypy.
|
# receive type hint information from mypy.
|
||||||
session.run("python", "-m", "pip", "uninstall", "--yes", "aiohttp")
|
session.run("python", "-m", "pip", "uninstall", "--yes", "aiohttp")
|
||||||
session.run("mypy", "--strict", "opensearch/")
|
session.run("mypy", "--strict", "opensearchpy/")
|
||||||
session.run("mypy", "--strict", "test_opensearch/test_types/sync_types.py")
|
session.run("mypy", "--strict", "test_opensearchpy/test_types/sync_types.py")
|
||||||
|
|
||||||
|
|
||||||
@nox.session()
|
@nox.session()
|
||||||
|
|||||||
@@ -52,13 +52,13 @@ class AsyncOpenSearch(object):
|
|||||||
|
|
||||||
The instance has attributes ``cat``, ``cluster``, ``indices``, ``ingest``,
|
The instance has attributes ``cat``, ``cluster``, ``indices``, ``ingest``,
|
||||||
``nodes``, ``snapshot`` and ``tasks`` that provide access to instances of
|
``nodes``, ``snapshot`` and ``tasks`` that provide access to instances of
|
||||||
:class:`~opensearch.client.CatClient`,
|
:class:`~opensearchpy.client.CatClient`,
|
||||||
:class:`~opensearch.client.ClusterClient`,
|
:class:`~opensearchpy.client.ClusterClient`,
|
||||||
:class:`~opensearch.client.IndicesClient`,
|
:class:`~opensearchpy.client.IndicesClient`,
|
||||||
:class:`~opensearch.client.IngestClient`,
|
:class:`~opensearchpy.client.IngestClient`,
|
||||||
:class:`~opensearch.client.NodesClient`,
|
:class:`~opensearchpy.client.NodesClient`,
|
||||||
:class:`~opensearch.client.SnapshotClient` and
|
:class:`~opensearchpy.client.SnapshotClient` and
|
||||||
:class:`~opensearch.client.TasksClient` respectively. This is the
|
:class:`~opensearchpy.client.TasksClient` respectively. This is the
|
||||||
preferred (and only supported) way to get access to those classes and their
|
preferred (and only supported) way to get access to those classes and their
|
||||||
methods.
|
methods.
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ class AsyncOpenSearch(object):
|
|||||||
client = OpenSearch(connection_class=ThriftConnection)
|
client = OpenSearch(connection_class=ThriftConnection)
|
||||||
|
|
||||||
If you want to turn on :ref:`sniffing` you have several options (described
|
If you want to turn on :ref:`sniffing` you have several options (described
|
||||||
in :class:`~opensearch.Transport`)::
|
in :class:`~opensearchpy.Transport`)::
|
||||||
|
|
||||||
# create connection that will automatically inspect the cluster to get
|
# create connection that will automatically inspect the cluster to get
|
||||||
# the list of active nodes. Start with nodes running on
|
# the list of active nodes. Start with nodes running on
|
||||||
@@ -95,7 +95,7 @@ class AsyncOpenSearch(object):
|
|||||||
])
|
])
|
||||||
|
|
||||||
If using SSL, there are several parameters that control how we deal with
|
If using SSL, there are several parameters that control how we deal with
|
||||||
certificates (see :class:`~opensearch.Urllib3HttpConnection` for
|
certificates (see :class:`~opensearchpy.Urllib3HttpConnection` for
|
||||||
detailed description of the options)::
|
detailed description of the options)::
|
||||||
|
|
||||||
client = OpenSearch(
|
client = OpenSearch(
|
||||||
@@ -109,7 +109,7 @@ class AsyncOpenSearch(object):
|
|||||||
)
|
)
|
||||||
|
|
||||||
If using SSL, but don't verify the certs, a warning message is showed
|
If using SSL, but don't verify the certs, a warning message is showed
|
||||||
optionally (see :class:`~opensearch.Urllib3HttpConnection` for
|
optionally (see :class:`~opensearchpy.Urllib3HttpConnection` for
|
||||||
detailed description of the options)::
|
detailed description of the options)::
|
||||||
|
|
||||||
client = OpenSearch(
|
client = OpenSearch(
|
||||||
@@ -123,7 +123,7 @@ class AsyncOpenSearch(object):
|
|||||||
)
|
)
|
||||||
|
|
||||||
SSL client authentication is supported
|
SSL client authentication is supported
|
||||||
(see :class:`~opensearch.Urllib3HttpConnection` for
|
(see :class:`~opensearchpy.Urllib3HttpConnection` for
|
||||||
detailed description of the options)::
|
detailed description of the options)::
|
||||||
|
|
||||||
client = OpenSearch(
|
client = OpenSearch(
|
||||||
@@ -156,7 +156,7 @@ class AsyncOpenSearch(object):
|
|||||||
is used to encode all outgoing requests.
|
is used to encode all outgoing requests.
|
||||||
However, you can implement your own custom serializer::
|
However, you can implement your own custom serializer::
|
||||||
|
|
||||||
from opensearch.serializer import JSONSerializer
|
from opensearchpy.serializer import JSONSerializer
|
||||||
|
|
||||||
class SetEncoder(JSONSerializer):
|
class SetEncoder(JSONSerializer):
|
||||||
def default(self, obj):
|
def default(self, obj):
|
||||||
@@ -174,16 +174,16 @@ class AsyncOpenSearch(object):
|
|||||||
"""
|
"""
|
||||||
:arg hosts: list of nodes, or a single node, we should connect to.
|
:arg hosts: list of nodes, or a single node, we should connect to.
|
||||||
Node should be a dictionary ({"host": "localhost", "port": 9200}),
|
Node should be a dictionary ({"host": "localhost", "port": 9200}),
|
||||||
the entire dictionary will be passed to the :class:`~opensearch.Connection`
|
the entire dictionary will be passed to the :class:`~opensearchpy.Connection`
|
||||||
class as kwargs, or a string in the format of ``host[:port]`` which will be
|
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
|
translated to a dictionary automatically. If no value is given the
|
||||||
:class:`~opensearch.Connection` class defaults will be used.
|
:class:`~opensearchpy.Connection` class defaults will be used.
|
||||||
|
|
||||||
:arg transport_class: :class:`~opensearch.Transport` subclass to use.
|
:arg transport_class: :class:`~opensearchpy.Transport` subclass to use.
|
||||||
|
|
||||||
:arg kwargs: any additional arguments will be passed on to the
|
:arg kwargs: any additional arguments will be passed on to the
|
||||||
:class:`~opensearch.Transport` class and, subsequently, to the
|
:class:`~opensearchpy.Transport` class and, subsequently, to the
|
||||||
:class:`~opensearch.Connection` instances.
|
:class:`~opensearchpy.Connection` instances.
|
||||||
"""
|
"""
|
||||||
self.transport = transport_class(_normalize_hosts(hosts), **kwargs)
|
self.transport = transport_class(_normalize_hosts(hosts), **kwargs)
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ from ..helpers.actions import (
|
|||||||
from ..helpers.errors import ScanError
|
from ..helpers.errors import ScanError
|
||||||
from .client import AsyncOpenSearch # noqa
|
from .client import AsyncOpenSearch # noqa
|
||||||
|
|
||||||
logger = logging.getLogger("opensearch.helpers")
|
logger = logging.getLogger("opensearchpy.helpers")
|
||||||
|
|
||||||
|
|
||||||
async def _chunk_actions(actions, chunk_size, max_chunk_bytes, serializer):
|
async def _chunk_actions(actions, chunk_size, max_chunk_bytes, serializer):
|
||||||
@@ -146,7 +146,7 @@ async def async_streaming_bulk(
|
|||||||
"""
|
"""
|
||||||
Streaming bulk consumes actions from the iterable passed in and yields
|
Streaming bulk consumes actions from the iterable passed in and yields
|
||||||
results per action. For non-streaming usecases use
|
results per action. For non-streaming usecases use
|
||||||
:func:`~opensearch.helpers.async_bulk` which is a wrapper around streaming
|
:func:`~opensearchpy.helpers.async_bulk` which is a wrapper around streaming
|
||||||
bulk that returns summary information about the bulk operation once the
|
bulk that returns summary information about the bulk operation once the
|
||||||
entire input is consumed and sent.
|
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
|
every subsequent rejection for the same chunk, for double the time every
|
||||||
time up to ``max_backoff`` seconds.
|
time up to ``max_backoff`` seconds.
|
||||||
|
|
||||||
:arg client: instance of :class:`~opensearch.AsyncOpenSearch` to use
|
:arg client: instance of :class:`~opensearchpy.AsyncOpenSearch` to use
|
||||||
:arg actions: iterable or async iterable containing the actions to be executed
|
:arg actions: iterable or async iterable containing the actions to be executed
|
||||||
:arg chunk_size: number of docs in one chunk sent to client (default: 500)
|
:arg chunk_size: number of docs in one chunk sent to client (default: 500)
|
||||||
:arg max_chunk_bytes: the maximum size of the request in bytes (default: 100MB)
|
:arg max_chunk_bytes: the maximum size of the request in bytes (default: 100MB)
|
||||||
@@ -242,7 +242,7 @@ async def async_bulk(
|
|||||||
client, actions, stats_only=False, ignore_status=(), *args, **kwargs
|
client, actions, stats_only=False, ignore_status=(), *args, **kwargs
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Helper for the :meth:`~opensearch.AsyncOpenSearch.bulk` api that provides
|
Helper for the :meth:`~opensearchpy.AsyncOpenSearch.bulk` api that provides
|
||||||
a more human friendly interface - it consumes an iterator of actions and
|
a more human friendly interface - it consumes an iterator of actions and
|
||||||
sends them to opensearch 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
|
information - number of successfully executed actions and either list of
|
||||||
@@ -254,19 +254,19 @@ async def async_bulk(
|
|||||||
When errors are being collected original document data is included in the
|
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
|
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
|
to process a lot of data and want to ignore/collect errors please consider
|
||||||
using the :func:`~opensearch.helpers.async_streaming_bulk` helper which will
|
using the :func:`~opensearchpy.helpers.async_streaming_bulk` helper which will
|
||||||
just return the errors and not store them in memory.
|
just return the errors and not store them in memory.
|
||||||
|
|
||||||
|
|
||||||
:arg client: instance of :class:`~opensearch.AsyncOpenSearch` to use
|
:arg client: instance of :class:`~opensearchpy.AsyncOpenSearch` to use
|
||||||
:arg actions: iterator containing the actions
|
:arg actions: iterator containing the actions
|
||||||
:arg stats_only: if `True` only report number of successful/failed
|
:arg stats_only: if `True` only report number of successful/failed
|
||||||
operations instead of just number of successful and a list of error responses
|
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
|
:arg ignore_status: list of HTTP status code that you want to ignore
|
||||||
|
|
||||||
Any additional keyword arguments will be passed to
|
Any additional keyword arguments will be passed to
|
||||||
:func:`~opensearch.helpers.async_streaming_bulk` which is used to execute
|
:func:`~opensearchpy.helpers.async_streaming_bulk` which is used to execute
|
||||||
the operation, see :func:`~opensearch.helpers.async_streaming_bulk` for more
|
the operation, see :func:`~opensearchpy.helpers.async_streaming_bulk` for more
|
||||||
accepted parameters.
|
accepted parameters.
|
||||||
"""
|
"""
|
||||||
success, failed = 0, 0
|
success, failed = 0, 0
|
||||||
@@ -304,7 +304,7 @@ async def async_scan(
|
|||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Simple abstraction on top of the
|
Simple abstraction on top of the
|
||||||
:meth:`~opensearch.AsyncOpenSearch.scroll` api - a simple iterator that
|
:meth:`~opensearchpy.AsyncOpenSearch.scroll` api - a simple iterator that
|
||||||
yields all hits as returned by underlining scroll requests.
|
yields all hits as returned by underlining scroll requests.
|
||||||
|
|
||||||
By default scan does not return results in any pre-determined order. To
|
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
|
may be an expensive operation and will negate the performance benefits of
|
||||||
using ``scan``.
|
using ``scan``.
|
||||||
|
|
||||||
:arg client: instance of :class:`~opensearch.AsyncOpenSearch` to use
|
:arg client: instance of :class:`~opensearchpy.AsyncOpenSearch` to use
|
||||||
:arg query: body for the :meth:`~opensearch.AsyncOpenSearch.search` api
|
:arg query: body for the :meth:`~opensearchpy.AsyncOpenSearch.search` api
|
||||||
:arg scroll: Specify how long a consistent view of the index should be
|
:arg scroll: Specify how long a consistent view of the index should be
|
||||||
maintained for scrolled search
|
maintained for scrolled search
|
||||||
:arg raise_on_error: raises an exception (``ScanError``) if an error is
|
: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
|
scroll API at the end of the method on completion or error, defaults
|
||||||
to true.
|
to true.
|
||||||
:arg scroll_kwargs: additional kwargs to be passed to
|
:arg scroll_kwargs: additional kwargs to be passed to
|
||||||
:meth:`~opensearch.AsyncOpenSearch.scroll`
|
:meth:`~opensearchpy.AsyncOpenSearch.scroll`
|
||||||
|
|
||||||
Any additional keyword arguments will be passed to the initial
|
Any additional keyword arguments will be passed to the initial
|
||||||
:meth:`~opensearch.AsyncOpenSearch.search` call::
|
:meth:`~opensearchpy.AsyncOpenSearch.search` call::
|
||||||
|
|
||||||
async_scan(client,
|
async_scan(client,
|
||||||
query={"query": {"match": {"title": "python"}}},
|
query={"query": {"match": {"title": "python"}}},
|
||||||
@@ -427,7 +427,7 @@ async def async_reindex(
|
|||||||
to another, potentially (if `target_client` is specified) on a different cluster.
|
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.
|
If you don't specify the query you will reindex all the documents.
|
||||||
|
|
||||||
Since ``2.3`` a :meth:`~opensearch.AsyncOpenSearch.reindex` api is
|
Since ``2.3`` a :meth:`~opensearchpy.AsyncOpenSearch.reindex` api is
|
||||||
available as part of opensearch itself. It is recommended to use the api
|
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
|
instead of this helper wherever possible. The helper is here mostly for
|
||||||
backwards compatibility and for situations where more flexibility is
|
backwards compatibility and for situations where more flexibility is
|
||||||
@@ -437,20 +437,20 @@ async def async_reindex(
|
|||||||
|
|
||||||
This helper doesn't transfer mappings, just the data.
|
This helper doesn't transfer mappings, just the data.
|
||||||
|
|
||||||
:arg client: instance of :class:`~opensearch.AsyncOpenSearch` to use (for
|
:arg client: instance of :class:`~opensearchpy.AsyncOpenSearch` to use (for
|
||||||
read if `target_client` is specified as well)
|
read if `target_client` is specified as well)
|
||||||
:arg source_index: index (or list of indices) to read documents from
|
: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 target_index: name of the index in the target cluster to populate
|
||||||
:arg query: body for the :meth:`~opensearch.AsyncOpenSearch.search` api
|
:arg query: body for the :meth:`~opensearchpy.AsyncOpenSearch.search` api
|
||||||
:arg target_client: optional, is specified will be used for writing (thus
|
:arg target_client: optional, is specified will be used for writing (thus
|
||||||
enabling reindex between clusters)
|
enabling reindex between clusters)
|
||||||
:arg chunk_size: number of docs in one chunk sent to client (default: 500)
|
:arg chunk_size: number of docs in one chunk sent to client (default: 500)
|
||||||
:arg scroll: Specify how long a consistent view of the index should be
|
:arg scroll: Specify how long a consistent view of the index should be
|
||||||
maintained for scrolled search
|
maintained for scrolled search
|
||||||
:arg scan_kwargs: additional kwargs to be passed to
|
:arg scan_kwargs: additional kwargs to be passed to
|
||||||
:func:`~opensearch.helpers.async_scan`
|
:func:`~opensearchpy.helpers.async_scan`
|
||||||
:arg bulk_kwargs: additional kwargs to be passed to
|
:arg bulk_kwargs: additional kwargs to be passed to
|
||||||
:func:`~opensearch.helpers.async_bulk`
|
:func:`~opensearchpy.helpers.async_bulk`
|
||||||
"""
|
"""
|
||||||
target_client = client if target_client is None else target_client
|
target_client = client if target_client is None else target_client
|
||||||
docs = async_scan(
|
docs = async_scan(
|
||||||
@@ -56,8 +56,8 @@ class AsyncTransport(Transport):
|
|||||||
"""
|
"""
|
||||||
:arg hosts: list of dictionaries, each containing keyword arguments to
|
:arg hosts: list of dictionaries, each containing keyword arguments to
|
||||||
create a `connection_class` instance
|
create a `connection_class` instance
|
||||||
:arg connection_class: subclass of :class:`~opensearch.Connection` to use
|
:arg connection_class: subclass of :class:`~opensearchpy.Connection` to use
|
||||||
:arg connection_pool_class: subclass of :class:`~opensearch.ConnectionPool` to use
|
:arg connection_pool_class: subclass of :class:`~opensearchpy.ConnectionPool` to use
|
||||||
:arg host_info_callback: callback responsible for taking the node information from
|
:arg host_info_callback: callback responsible for taking the node information from
|
||||||
`/_cluster/nodes`, along with already extracted information, and
|
`/_cluster/nodes`, along with already extracted information, and
|
||||||
producing a list of arguments (same as `hosts` parameter)
|
producing a list of arguments (same as `hosts` parameter)
|
||||||
@@ -300,7 +300,7 @@ class AsyncTransport(Transport):
|
|||||||
Mark a connection as dead (failed) in the connection pool. If sniffing
|
Mark a connection as dead (failed) in the connection pool. If sniffing
|
||||||
on failure is enabled this will initiate the sniffing process.
|
on failure is enabled this will initiate the sniffing process.
|
||||||
|
|
||||||
:arg connection: instance of :class:`~opensearch.Connection` that failed
|
:arg connection: instance of :class:`~opensearchpy.Connection` that failed
|
||||||
"""
|
"""
|
||||||
self.connection_pool.mark_dead(connection)
|
self.connection_pool.mark_dead(connection)
|
||||||
if self.sniff_on_connection_fail:
|
if self.sniff_on_connection_fail:
|
||||||
@@ -324,9 +324,9 @@ class AsyncTransport(Transport):
|
|||||||
:arg method: HTTP method to use
|
:arg method: HTTP method to use
|
||||||
:arg url: absolute url (without host) to target
|
:arg url: absolute url (without host) to target
|
||||||
:arg headers: dictionary of headers, will be handed over to the
|
:arg headers: dictionary of headers, will be handed over to the
|
||||||
underlying :class:`~opensearch.Connection` class
|
underlying :class:`~opensearchpy.Connection` class
|
||||||
:arg params: dictionary of query parameters, will be handed over to the
|
:arg params: dictionary of query parameters, will be handed over to the
|
||||||
underlying :class:`~opensearch.Connection` class for serialization
|
underlying :class:`~opensearchpy.Connection` class for serialization
|
||||||
:arg body: body of the request, will be serialized using serializer and
|
:arg body: body of the request, will be serialized using serializer and
|
||||||
passed to the connection
|
passed to the connection
|
||||||
"""
|
"""
|
||||||
@@ -52,13 +52,13 @@ class OpenSearch(object):
|
|||||||
|
|
||||||
The instance has attributes ``cat``, ``cluster``, ``indices``, ``ingest``,
|
The instance has attributes ``cat``, ``cluster``, ``indices``, ``ingest``,
|
||||||
``nodes``, ``snapshot`` and ``tasks`` that provide access to instances of
|
``nodes``, ``snapshot`` and ``tasks`` that provide access to instances of
|
||||||
:class:`~opensearch.client.CatClient`,
|
:class:`~opensearchpy.client.CatClient`,
|
||||||
:class:`~opensearch.client.ClusterClient`,
|
:class:`~opensearchpy.client.ClusterClient`,
|
||||||
:class:`~opensearch.client.IndicesClient`,
|
:class:`~opensearchpy.client.IndicesClient`,
|
||||||
:class:`~opensearch.client.IngestClient`,
|
:class:`~opensearchpy.client.IngestClient`,
|
||||||
:class:`~opensearch.client.NodesClient`,
|
:class:`~opensearchpy.client.NodesClient`,
|
||||||
:class:`~opensearch.client.SnapshotClient` and
|
:class:`~opensearchpy.client.SnapshotClient` and
|
||||||
:class:`~opensearch.client.TasksClient` respectively. This is the
|
:class:`~opensearchpy.client.TasksClient` respectively. This is the
|
||||||
preferred (and only supported) way to get access to those classes and their
|
preferred (and only supported) way to get access to those classes and their
|
||||||
methods.
|
methods.
|
||||||
|
|
||||||
@@ -69,7 +69,7 @@ class OpenSearch(object):
|
|||||||
client = OpenSearch(connection_class=ThriftConnection)
|
client = OpenSearch(connection_class=ThriftConnection)
|
||||||
|
|
||||||
If you want to turn on :ref:`sniffing` you have several options (described
|
If you want to turn on :ref:`sniffing` you have several options (described
|
||||||
in :class:`~opensearch.Transport`)::
|
in :class:`~opensearchpy.Transport`)::
|
||||||
|
|
||||||
# create connection that will automatically inspect the cluster to get
|
# create connection that will automatically inspect the cluster to get
|
||||||
# the list of active nodes. Start with nodes running on
|
# the list of active nodes. Start with nodes running on
|
||||||
@@ -95,7 +95,7 @@ class OpenSearch(object):
|
|||||||
])
|
])
|
||||||
|
|
||||||
If using SSL, there are several parameters that control how we deal with
|
If using SSL, there are several parameters that control how we deal with
|
||||||
certificates (see :class:`~opensearch.Urllib3HttpConnection` for
|
certificates (see :class:`~opensearchpy.Urllib3HttpConnection` for
|
||||||
detailed description of the options)::
|
detailed description of the options)::
|
||||||
|
|
||||||
client = OpenSearch(
|
client = OpenSearch(
|
||||||
@@ -109,7 +109,7 @@ class OpenSearch(object):
|
|||||||
)
|
)
|
||||||
|
|
||||||
If using SSL, but don't verify the certs, a warning message is showed
|
If using SSL, but don't verify the certs, a warning message is showed
|
||||||
optionally (see :class:`~opensearch.Urllib3HttpConnection` for
|
optionally (see :class:`~opensearchpy.Urllib3HttpConnection` for
|
||||||
detailed description of the options)::
|
detailed description of the options)::
|
||||||
|
|
||||||
client = OpenSearch(
|
client = OpenSearch(
|
||||||
@@ -123,7 +123,7 @@ class OpenSearch(object):
|
|||||||
)
|
)
|
||||||
|
|
||||||
SSL client authentication is supported
|
SSL client authentication is supported
|
||||||
(see :class:`~opensearch.Urllib3HttpConnection` for
|
(see :class:`~opensearchpy.Urllib3HttpConnection` for
|
||||||
detailed description of the options)::
|
detailed description of the options)::
|
||||||
|
|
||||||
client = OpenSearch(
|
client = OpenSearch(
|
||||||
@@ -156,7 +156,7 @@ class OpenSearch(object):
|
|||||||
is used to encode all outgoing requests.
|
is used to encode all outgoing requests.
|
||||||
However, you can implement your own custom serializer::
|
However, you can implement your own custom serializer::
|
||||||
|
|
||||||
from opensearch.serializer import JSONSerializer
|
from opensearchpy.serializer import JSONSerializer
|
||||||
|
|
||||||
class SetEncoder(JSONSerializer):
|
class SetEncoder(JSONSerializer):
|
||||||
def default(self, obj):
|
def default(self, obj):
|
||||||
@@ -174,16 +174,16 @@ class OpenSearch(object):
|
|||||||
"""
|
"""
|
||||||
:arg hosts: list of nodes, or a single node, we should connect to.
|
:arg hosts: list of nodes, or a single node, we should connect to.
|
||||||
Node should be a dictionary ({"host": "localhost", "port": 9200}),
|
Node should be a dictionary ({"host": "localhost", "port": 9200}),
|
||||||
the entire dictionary will be passed to the :class:`~opensearch.Connection`
|
the entire dictionary will be passed to the :class:`~opensearchpy.Connection`
|
||||||
class as kwargs, or a string in the format of ``host[:port]`` which will be
|
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
|
translated to a dictionary automatically. If no value is given the
|
||||||
:class:`~opensearch.Connection` class defaults will be used.
|
:class:`~opensearchpy.Connection` class defaults will be used.
|
||||||
|
|
||||||
:arg transport_class: :class:`~opensearch.Transport` subclass to use.
|
:arg transport_class: :class:`~opensearchpy.Transport` subclass to use.
|
||||||
|
|
||||||
:arg kwargs: any additional arguments will be passed on to the
|
:arg kwargs: any additional arguments will be passed on to the
|
||||||
:class:`~opensearch.Transport` class and, subsequently, to the
|
:class:`~opensearchpy.Transport` class and, subsequently, to the
|
||||||
:class:`~opensearch.Connection` instances.
|
:class:`~opensearchpy.Connection` instances.
|
||||||
"""
|
"""
|
||||||
self.transport = transport_class(_normalize_hosts(hosts), **kwargs)
|
self.transport = transport_class(_normalize_hosts(hosts), **kwargs)
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ SKIP_IN_PATH = (None, "", b"", [], ())
|
|||||||
def _normalize_hosts(hosts):
|
def _normalize_hosts(hosts):
|
||||||
"""
|
"""
|
||||||
Helper function to transform hosts argument to
|
Helper function to transform hosts argument to
|
||||||
:class:`~opensearch.OpenSearch` to a list of dicts.
|
:class:`~opensearchpy.OpenSearch` to a list of dicts.
|
||||||
"""
|
"""
|
||||||
# if hosts are empty, just defer to defaults down the line
|
# if hosts are empty, just defer to defaults down the line
|
||||||
if hosts is None:
|
if hosts is None:
|
||||||
@@ -48,10 +48,10 @@ from ..exceptions import (
|
|||||||
|
|
||||||
logger = logging.getLogger("opensearch")
|
logger = logging.getLogger("opensearch")
|
||||||
|
|
||||||
# create the opensearch.trace logger, but only set propagate to False if the
|
# create the opensearchpy.trace logger, but only set propagate to False if the
|
||||||
# logger hasn't already been configured
|
# logger hasn't already been configured
|
||||||
_tracer_already_configured = "opensearch.trace" in logging.Logger.manager.loggerDict
|
_tracer_already_configured = "opensearchpy.trace" in logging.Logger.manager.loggerDict
|
||||||
tracer = logging.getLogger("opensearch.trace")
|
tracer = logging.getLogger("opensearchpy.trace")
|
||||||
if not _tracer_already_configured:
|
if not _tracer_already_configured:
|
||||||
tracer.propagate = False
|
tracer.propagate = False
|
||||||
|
|
||||||
@@ -48,7 +48,7 @@ class ConnectionSelector(object):
|
|||||||
*currently* live connections to choose from.
|
*currently* live connections to choose from.
|
||||||
|
|
||||||
The options dictionary is the one that has been passed to
|
The options dictionary is the one that has been passed to
|
||||||
:class:`~opensearch.Transport` as `hosts` param and the same that is
|
:class:`~opensearchpy.Transport` as `hosts` param and the same that is
|
||||||
used to construct the Connection object itself. When the Connection was
|
used to construct the Connection object itself. When the Connection was
|
||||||
created from information retrieved from the cluster via the sniffing
|
created from information retrieved from the cluster via the sniffing
|
||||||
process it will be the dictionary returned by the `host_info_callback`.
|
process it will be the dictionary returned by the `host_info_callback`.
|
||||||
@@ -99,11 +99,11 @@ class RoundRobinSelector(ConnectionSelector):
|
|||||||
|
|
||||||
class ConnectionPool(object):
|
class ConnectionPool(object):
|
||||||
"""
|
"""
|
||||||
Container holding the :class:`~opensearch.Connection` instances,
|
Container holding the :class:`~opensearchpy.Connection` instances,
|
||||||
managing the selection process (via a
|
managing the selection process (via a
|
||||||
:class:`~opensearch.ConnectionSelector`) and dead connections.
|
:class:`~opensearchpy.ConnectionSelector`) and dead connections.
|
||||||
|
|
||||||
It's only interactions are with the :class:`~opensearch.Transport` class
|
It's only interactions are with the :class:`~opensearchpy.Transport` class
|
||||||
that drives all the actions within `ConnectionPool`.
|
that drives all the actions within `ConnectionPool`.
|
||||||
|
|
||||||
Initially connections are stored on the class as a list and, along with the
|
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
|
:arg connections: list of tuples containing the
|
||||||
:class:`~opensearch.Connection` instance and it's options
|
:class:`~opensearchpy.Connection` instance and it's options
|
||||||
:arg dead_timeout: number of seconds a connection should be retired for
|
:arg dead_timeout: number of seconds a connection should be retired for
|
||||||
after a failure, increases on consecutive failures
|
after a failure, increases on consecutive failures
|
||||||
:arg timeout_cutoff: number of consecutive failures after which the
|
:arg timeout_cutoff: number of consecutive failures after which the
|
||||||
timeout doesn't increase
|
timeout doesn't increase
|
||||||
:arg selector_class: :class:`~opensearch.ConnectionSelector`
|
:arg selector_class: :class:`~opensearchpy.ConnectionSelector`
|
||||||
subclass to use if more than one connection is live
|
subclass to use if more than one connection is live
|
||||||
:arg randomize_hosts: shuffle the list of connections upon arrival to
|
:arg randomize_hosts: shuffle the list of connections upon arrival to
|
||||||
avoid dog piling effect across processes
|
avoid dog piling effect across processes
|
||||||
@@ -49,7 +49,7 @@ class ImproperlyConfigured(Exception):
|
|||||||
class OpenSearchException(Exception):
|
class OpenSearchException(Exception):
|
||||||
"""
|
"""
|
||||||
Base class for all exceptions raised by this package's operations (doesn't
|
Base class for all exceptions raised by this package's operations (doesn't
|
||||||
apply to :class:`~opensearch.ImproperlyConfigured`).
|
apply to :class:`~opensearchpy.ImproperlyConfigured`).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
@@ -116,7 +116,7 @@ class TransportError(OpenSearchException):
|
|||||||
class ConnectionError(TransportError):
|
class ConnectionError(TransportError):
|
||||||
"""
|
"""
|
||||||
Error raised when there was an exception while talking to OpenSearch. Original
|
Error raised when there was an exception while talking to OpenSearch. Original
|
||||||
exception from the underlying :class:`~opensearch.Connection`
|
exception from the underlying :class:`~opensearchpy.Connection`
|
||||||
implementation is available as ``.info``.
|
implementation is available as ``.info``.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -32,14 +32,14 @@ from ..compat import Mapping, Queue, map, string_types
|
|||||||
from ..exceptions import TransportError
|
from ..exceptions import TransportError
|
||||||
from .errors import BulkIndexError, ScanError
|
from .errors import BulkIndexError, ScanError
|
||||||
|
|
||||||
logger = logging.getLogger("opensearch.helpers")
|
logger = logging.getLogger("opensearchpy.helpers")
|
||||||
|
|
||||||
|
|
||||||
def expand_action(data):
|
def expand_action(data):
|
||||||
"""
|
"""
|
||||||
From one document or action definition passed in by the user extract the
|
From one document or action definition passed in by the user extract the
|
||||||
action/data lines needed for opensearch's
|
action/data lines needed for opensearch's
|
||||||
:meth:`~opensearch.OpenSearch.bulk` api.
|
:meth:`~opensearchpy.OpenSearch.bulk` api.
|
||||||
"""
|
"""
|
||||||
# when given a string, assume user wants to index raw json
|
# when given a string, assume user wants to index raw json
|
||||||
if isinstance(data, string_types):
|
if isinstance(data, string_types):
|
||||||
@@ -284,7 +284,7 @@ def streaming_bulk(
|
|||||||
"""
|
"""
|
||||||
Streaming bulk consumes actions from the iterable passed in and yields
|
Streaming bulk consumes actions from the iterable passed in and yields
|
||||||
results per action. For non-streaming usecases use
|
results per action. For non-streaming usecases use
|
||||||
:func:`~opensearch.helpers.bulk` which is a wrapper around streaming
|
:func:`~opensearchpy.helpers.bulk` which is a wrapper around streaming
|
||||||
bulk that returns summary information about the bulk operation once the
|
bulk that returns summary information about the bulk operation once the
|
||||||
entire input is consumed and sent.
|
entire input is consumed and sent.
|
||||||
|
|
||||||
@@ -294,7 +294,7 @@ def streaming_bulk(
|
|||||||
every subsequent rejection for the same chunk, for double the time every
|
every subsequent rejection for the same chunk, for double the time every
|
||||||
time up to ``max_backoff`` seconds.
|
time up to ``max_backoff`` seconds.
|
||||||
|
|
||||||
:arg client: instance of :class:`~opensearch.OpenSearch` to use
|
:arg client: instance of :class:`~opensearchpy.OpenSearch` to use
|
||||||
:arg actions: iterable containing the actions to be executed
|
:arg actions: iterable containing the actions to be executed
|
||||||
:arg chunk_size: number of docs in one chunk sent to client (default: 500)
|
:arg chunk_size: number of docs in one chunk sent to client (default: 500)
|
||||||
:arg max_chunk_bytes: the maximum size of the request in bytes (default: 100MB)
|
:arg max_chunk_bytes: the maximum size of the request in bytes (default: 100MB)
|
||||||
@@ -373,7 +373,7 @@ def streaming_bulk(
|
|||||||
|
|
||||||
def bulk(client, actions, stats_only=False, ignore_status=(), *args, **kwargs):
|
def bulk(client, actions, stats_only=False, ignore_status=(), *args, **kwargs):
|
||||||
"""
|
"""
|
||||||
Helper for the :meth:`~opensearch.OpenSearch.bulk` api that provides
|
Helper for the :meth:`~opensearchpy.OpenSearch.bulk` api that provides
|
||||||
a more human friendly interface - it consumes an iterator of actions and
|
a more human friendly interface - it consumes an iterator of actions and
|
||||||
sends them to opensearch 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
|
information - number of successfully executed actions and either list of
|
||||||
@@ -385,19 +385,19 @@ def bulk(client, actions, stats_only=False, ignore_status=(), *args, **kwargs):
|
|||||||
When errors are being collected original document data is included in the
|
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
|
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
|
to process a lot of data and want to ignore/collect errors please consider
|
||||||
using the :func:`~opensearch.helpers.streaming_bulk` helper which will
|
using the :func:`~opensearchpy.helpers.streaming_bulk` helper which will
|
||||||
just return the errors and not store them in memory.
|
just return the errors and not store them in memory.
|
||||||
|
|
||||||
|
|
||||||
:arg client: instance of :class:`~opensearch.OpenSearch` to use
|
:arg client: instance of :class:`~opensearchpy.OpenSearch` to use
|
||||||
:arg actions: iterator containing the actions
|
:arg actions: iterator containing the actions
|
||||||
:arg stats_only: if `True` only report number of successful/failed
|
:arg stats_only: if `True` only report number of successful/failed
|
||||||
operations instead of just number of successful and a list of error responses
|
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
|
:arg ignore_status: list of HTTP status code that you want to ignore
|
||||||
|
|
||||||
Any additional keyword arguments will be passed to
|
Any additional keyword arguments will be passed to
|
||||||
:func:`~opensearch.helpers.streaming_bulk` which is used to execute
|
:func:`~opensearchpy.helpers.streaming_bulk` which is used to execute
|
||||||
the operation, see :func:`~opensearch.helpers.streaming_bulk` for more
|
the operation, see :func:`~opensearchpy.helpers.streaming_bulk` for more
|
||||||
accepted parameters.
|
accepted parameters.
|
||||||
"""
|
"""
|
||||||
success, failed = 0, 0
|
success, failed = 0, 0
|
||||||
@@ -436,7 +436,7 @@ def parallel_bulk(
|
|||||||
"""
|
"""
|
||||||
Parallel version of the bulk helper run in multiple threads at once.
|
Parallel version of the bulk helper run in multiple threads at once.
|
||||||
|
|
||||||
:arg client: instance of :class:`~opensearch.OpenSearch` to use
|
:arg client: instance of :class:`~opensearchpy.OpenSearch` to use
|
||||||
:arg actions: iterator containing the actions
|
:arg actions: iterator containing the actions
|
||||||
:arg thread_count: size of the threadpool to use for the bulk requests
|
:arg thread_count: size of the threadpool to use for the bulk requests
|
||||||
:arg chunk_size: number of docs in one chunk sent to client (default: 500)
|
:arg chunk_size: number of docs in one chunk sent to client (default: 500)
|
||||||
@@ -506,7 +506,7 @@ def scan(
|
|||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
Simple abstraction on top of the
|
Simple abstraction on top of the
|
||||||
:meth:`~opensearch.OpenSearch.scroll` api - a simple iterator that
|
:meth:`~opensearchpy.OpenSearch.scroll` api - a simple iterator that
|
||||||
yields all hits as returned by underlining scroll requests.
|
yields all hits as returned by underlining scroll requests.
|
||||||
|
|
||||||
By default scan does not return results in any pre-determined order. To
|
By default scan does not return results in any pre-determined order. To
|
||||||
@@ -515,8 +515,8 @@ def scan(
|
|||||||
may be an expensive operation and will negate the performance benefits of
|
may be an expensive operation and will negate the performance benefits of
|
||||||
using ``scan``.
|
using ``scan``.
|
||||||
|
|
||||||
:arg client: instance of :class:`~opensearch.OpenSearch` to use
|
:arg client: instance of :class:`~opensearchpy.OpenSearch` to use
|
||||||
:arg query: body for the :meth:`~opensearch.OpenSearch.search` api
|
:arg query: body for the :meth:`~opensearchpy.OpenSearch.search` api
|
||||||
:arg scroll: Specify how long a consistent view of the index should be
|
:arg scroll: Specify how long a consistent view of the index should be
|
||||||
maintained for scrolled search
|
maintained for scrolled search
|
||||||
:arg raise_on_error: raises an exception (``ScanError``) if an error is
|
:arg raise_on_error: raises an exception (``ScanError``) if an error is
|
||||||
@@ -531,10 +531,10 @@ def scan(
|
|||||||
scroll API at the end of the method on completion or error, defaults
|
scroll API at the end of the method on completion or error, defaults
|
||||||
to true.
|
to true.
|
||||||
:arg scroll_kwargs: additional kwargs to be passed to
|
:arg scroll_kwargs: additional kwargs to be passed to
|
||||||
:meth:`~opensearch.OpenSearch.scroll`
|
:meth:`~opensearchpy.OpenSearch.scroll`
|
||||||
|
|
||||||
Any additional keyword arguments will be passed to the initial
|
Any additional keyword arguments will be passed to the initial
|
||||||
:meth:`~opensearch.OpenSearch.search` call::
|
:meth:`~opensearchpy.OpenSearch.search` call::
|
||||||
|
|
||||||
scan(client,
|
scan(client,
|
||||||
query={"query": {"match": {"title": "python"}}},
|
query={"query": {"match": {"title": "python"}}},
|
||||||
@@ -627,7 +627,7 @@ def reindex(
|
|||||||
to another, potentially (if `target_client` is specified) on a different cluster.
|
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.
|
If you don't specify the query you will reindex all the documents.
|
||||||
|
|
||||||
Since ``2.3`` a :meth:`~opensearch.OpenSearch.reindex` api is
|
Since ``2.3`` a :meth:`~opensearchpy.OpenSearch.reindex` api is
|
||||||
available as part of opensearch itself. It is recommended to use the api
|
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
|
instead of this helper wherever possible. The helper is here mostly for
|
||||||
backwards compatibility and for situations where more flexibility is
|
backwards compatibility and for situations where more flexibility is
|
||||||
@@ -637,20 +637,20 @@ def reindex(
|
|||||||
|
|
||||||
This helper doesn't transfer mappings, just the data.
|
This helper doesn't transfer mappings, just the data.
|
||||||
|
|
||||||
:arg client: instance of :class:`~opensearch.OpenSearch` to use (for
|
:arg client: instance of :class:`~opensearchpy.OpenSearch` to use (for
|
||||||
read if `target_client` is specified as well)
|
read if `target_client` is specified as well)
|
||||||
:arg source_index: index (or list of indices) to read documents from
|
: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 target_index: name of the index in the target cluster to populate
|
||||||
:arg query: body for the :meth:`~opensearch.OpenSearch.search` api
|
:arg query: body for the :meth:`~opensearchpy.OpenSearch.search` api
|
||||||
:arg target_client: optional, is specified will be used for writing (thus
|
:arg target_client: optional, is specified will be used for writing (thus
|
||||||
enabling reindex between clusters)
|
enabling reindex between clusters)
|
||||||
:arg chunk_size: number of docs in one chunk sent to client (default: 500)
|
:arg chunk_size: number of docs in one chunk sent to client (default: 500)
|
||||||
:arg scroll: Specify how long a consistent view of the index should be
|
:arg scroll: Specify how long a consistent view of the index should be
|
||||||
maintained for scrolled search
|
maintained for scrolled search
|
||||||
:arg scan_kwargs: additional kwargs to be passed to
|
:arg scan_kwargs: additional kwargs to be passed to
|
||||||
:func:`~opensearch.helpers.scan`
|
:func:`~opensearchpy.helpers.scan`
|
||||||
:arg bulk_kwargs: additional kwargs to be passed to
|
:arg bulk_kwargs: additional kwargs to be passed to
|
||||||
:func:`~opensearch.helpers.bulk`
|
:func:`~opensearchpy.helpers.bulk`
|
||||||
"""
|
"""
|
||||||
target_client = client if target_client is None else target_client
|
target_client = client if target_client is None else target_client
|
||||||
docs = scan(client, query=query, index=source_index, scroll=scroll, **scan_kwargs)
|
docs = scan(client, query=query, index=source_index, scroll=scroll, **scan_kwargs)
|
||||||
@@ -31,8 +31,8 @@ import time
|
|||||||
from os.path import abspath, dirname, join
|
from os.path import abspath, dirname, join
|
||||||
from unittest import SkipTest, TestCase
|
from unittest import SkipTest, TestCase
|
||||||
|
|
||||||
from opensearch import OpenSearch
|
from opensearchpy import OpenSearch
|
||||||
from opensearch.exceptions import ConnectionError
|
from opensearchpy.exceptions import ConnectionError
|
||||||
|
|
||||||
if "OPENSEARCH_URL" in os.environ:
|
if "OPENSEARCH_URL" in os.environ:
|
||||||
OPENSEARCH_URL = os.environ["OPENSEARCH_URL"]
|
OPENSEARCH_URL = os.environ["OPENSEARCH_URL"]
|
||||||
@@ -47,7 +47,7 @@ def get_test_client(nowait=False, **kwargs):
|
|||||||
kw = {"timeout": 30, "ca_certs": CA_CERTS}
|
kw = {"timeout": 30, "ca_certs": CA_CERTS}
|
||||||
|
|
||||||
if "PYTHON_CONNECTION_CLASS" in os.environ:
|
if "PYTHON_CONNECTION_CLASS" in os.environ:
|
||||||
from opensearch import connection
|
from opensearchpy import connection
|
||||||
|
|
||||||
kw["connection_class"] = getattr(
|
kw["connection_class"] = getattr(
|
||||||
connection, os.environ["PYTHON_CONNECTION_CLASS"]
|
connection, os.environ["PYTHON_CONNECTION_CLASS"]
|
||||||
@@ -45,7 +45,7 @@ def get_host_info(node_info, host):
|
|||||||
`None` is returned this node will be skipped.
|
`None` is returned this node will be skipped.
|
||||||
|
|
||||||
Useful for filtering nodes (by proximity for example) or if additional
|
Useful for filtering nodes (by proximity for example) or if additional
|
||||||
information needs to be provided for the :class:`~opensearch.Connection`
|
information needs to be provided for the :class:`~opensearchpy.Connection`
|
||||||
class. By default master only nodes are filtered out since they shouldn't
|
class. By default master only nodes are filtered out since they shouldn't
|
||||||
typically be used for API operations.
|
typically be used for API operations.
|
||||||
|
|
||||||
@@ -90,8 +90,8 @@ class Transport(object):
|
|||||||
"""
|
"""
|
||||||
:arg hosts: list of dictionaries, each containing keyword arguments to
|
:arg hosts: list of dictionaries, each containing keyword arguments to
|
||||||
create a `connection_class` instance
|
create a `connection_class` instance
|
||||||
:arg connection_class: subclass of :class:`~opensearch.Connection` to use
|
:arg connection_class: subclass of :class:`~opensearchpy.Connection` to use
|
||||||
:arg connection_pool_class: subclass of :class:`~opensearch.ConnectionPool` to use
|
:arg connection_pool_class: subclass of :class:`~opensearchpy.ConnectionPool` to use
|
||||||
:arg host_info_callback: callback responsible for taking the node information from
|
:arg host_info_callback: callback responsible for taking the node information from
|
||||||
`/_cluster/nodes`, along with already extracted information, and
|
`/_cluster/nodes`, along with already extracted information, and
|
||||||
producing a list of arguments (same as `hosts` parameter)
|
producing a list of arguments (same as `hosts` parameter)
|
||||||
@@ -186,7 +186,7 @@ class Transport(object):
|
|||||||
|
|
||||||
def add_connection(self, host):
|
def add_connection(self, host):
|
||||||
"""
|
"""
|
||||||
Create a new :class:`~opensearch.Connection` instance and add it to the pool.
|
Create a new :class:`~opensearchpy.Connection` instance and add it to the pool.
|
||||||
|
|
||||||
:arg host: kwargs that will be used to create the instance
|
:arg host: kwargs that will be used to create the instance
|
||||||
"""
|
"""
|
||||||
@@ -197,7 +197,7 @@ class Transport(object):
|
|||||||
"""
|
"""
|
||||||
Instantiate all the connections and create new connection pool to hold them.
|
Instantiate all the connections and create new connection pool to hold them.
|
||||||
Tries to identify unchanged hosts and re-use existing
|
Tries to identify unchanged hosts and re-use existing
|
||||||
:class:`~opensearch.Connection` instances.
|
:class:`~opensearchpy.Connection` instances.
|
||||||
|
|
||||||
:arg hosts: same as `__init__`
|
:arg hosts: same as `__init__`
|
||||||
"""
|
"""
|
||||||
@@ -229,8 +229,8 @@ class Transport(object):
|
|||||||
|
|
||||||
def get_connection(self):
|
def get_connection(self):
|
||||||
"""
|
"""
|
||||||
Retrieve a :class:`~opensearch.Connection` instance from the
|
Retrieve a :class:`~opensearchpy.Connection` instance from the
|
||||||
:class:`~opensearch.ConnectionPool` instance.
|
:class:`~opensearchpy.ConnectionPool` instance.
|
||||||
"""
|
"""
|
||||||
if self.sniffer_timeout:
|
if self.sniffer_timeout:
|
||||||
if time.time() >= self.last_sniff + self.sniffer_timeout:
|
if time.time() >= self.last_sniff + self.sniffer_timeout:
|
||||||
@@ -334,7 +334,7 @@ class Transport(object):
|
|||||||
Mark a connection as dead (failed) in the connection pool. If sniffing
|
Mark a connection as dead (failed) in the connection pool. If sniffing
|
||||||
on failure is enabled this will initiate the sniffing process.
|
on failure is enabled this will initiate the sniffing process.
|
||||||
|
|
||||||
:arg connection: instance of :class:`~opensearch.Connection` that failed
|
:arg connection: instance of :class:`~opensearchpy.Connection` that failed
|
||||||
"""
|
"""
|
||||||
# mark as dead even when sniffing to avoid hitting this host during the sniff process
|
# mark as dead even when sniffing to avoid hitting this host during the sniff process
|
||||||
self.connection_pool.mark_dead(connection)
|
self.connection_pool.mark_dead(connection)
|
||||||
@@ -356,9 +356,9 @@ class Transport(object):
|
|||||||
:arg method: HTTP method to use
|
:arg method: HTTP method to use
|
||||||
:arg url: absolute url (without host) to target
|
:arg url: absolute url (without host) to target
|
||||||
:arg headers: dictionary of headers, will be handed over to the
|
:arg headers: dictionary of headers, will be handed over to the
|
||||||
underlying :class:`~opensearch.Connection` class
|
underlying :class:`~opensearchpy.Connection` class
|
||||||
:arg params: dictionary of query parameters, will be handed over to the
|
:arg params: dictionary of query parameters, will be handed over to the
|
||||||
underlying :class:`~opensearch.Connection` class for serialization
|
underlying :class:`~opensearchpy.Connection` class for serialization
|
||||||
:arg body: body of the request, will be serialized using serializer and
|
:arg body: body of the request, will be serialized using serializer and
|
||||||
passed to the connection
|
passed to the connection
|
||||||
"""
|
"""
|
||||||
@@ -30,7 +30,7 @@ from os.path import abspath, dirname, join
|
|||||||
|
|
||||||
from setuptools import find_packages, setup
|
from setuptools import find_packages, setup
|
||||||
|
|
||||||
package_name = "opensearch"
|
package_name = "opensearchpy"
|
||||||
base_dir = abspath(dirname(__file__))
|
base_dir = abspath(dirname(__file__))
|
||||||
|
|
||||||
with open(join(base_dir, package_name, "_version.py")) as f:
|
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 = [
|
packages = [
|
||||||
package
|
package
|
||||||
for package in find_packages(where=".", exclude=("test_opensearch*",))
|
for package in find_packages(where=".", exclude=("test_opensearchpy*",))
|
||||||
if package == package_name or package.startswith(package_name + ".")
|
if package == package_name or package.startswith(package_name + ".")
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -82,7 +82,7 @@ setup(
|
|||||||
"Issue Tracker": "https://github.com/opensearch-project/opensearch-py/issues",
|
"Issue Tracker": "https://github.com/opensearch-project/opensearch-py/issues",
|
||||||
},
|
},
|
||||||
packages=packages,
|
packages=packages,
|
||||||
package_data={"opensearch": ["py.typed", "*.pyi"]},
|
package_data={"opensearchpy": ["py.typed", "*.pyi"]},
|
||||||
include_package_data=True,
|
include_package_data=True,
|
||||||
zip_safe=False,
|
zip_safe=False,
|
||||||
classifiers=[
|
classifiers=[
|
||||||
@@ -105,7 +105,7 @@ setup(
|
|||||||
],
|
],
|
||||||
python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, <4",
|
python_requires=">=2.7, !=3.0.*, !=3.1.*, !=3.2.*, !=3.3.*, <4",
|
||||||
install_requires=install_requires,
|
install_requires=install_requires,
|
||||||
test_suite="test_opensearch.run_tests.run_all",
|
test_suite="test_opensearchpy.run_tests.run_all",
|
||||||
tests_require=tests_require,
|
tests_require=tests_require,
|
||||||
extras_require={
|
extras_require={
|
||||||
"develop": tests_require + docs_require + generate_require,
|
"develop": tests_require + docs_require + generate_require,
|
||||||
|
|||||||
@@ -59,8 +59,8 @@ def fetch_opensearch_repo():
|
|||||||
if environ.get("TEST_OPENSEARCH_NOFETCH", False):
|
if environ.get("TEST_OPENSEARCH_NOFETCH", False):
|
||||||
return
|
return
|
||||||
|
|
||||||
from test_opensearch.test_cases import SkipTest
|
from test_opensearchpy.test_cases import SkipTest
|
||||||
from test_opensearch.test_server import get_client
|
from test_opensearchpy.test_server import get_client
|
||||||
|
|
||||||
# find out the sha of the running client
|
# find out the sha of the running client
|
||||||
try:
|
try:
|
||||||
@@ -110,15 +110,15 @@ def run_all(argv=None):
|
|||||||
ignores = []
|
ignores = []
|
||||||
# Python 3.6+ is required for async
|
# Python 3.6+ is required for async
|
||||||
if sys.version_info < (3, 6):
|
if sys.version_info < (3, 6):
|
||||||
ignores.append("test_opensearch/test_async/")
|
ignores.append("test_opensearchpy/test_async/")
|
||||||
|
|
||||||
# GitHub Actions, run non-server tests
|
# GitHub Actions, run non-server tests
|
||||||
if "GITHUB_ACTION" in environ:
|
if "GITHUB_ACTION" in environ:
|
||||||
ignores.extend(
|
ignores.extend(
|
||||||
[
|
[
|
||||||
"test_opensearch/test_server/",
|
"test_opensearchpy/test_server/",
|
||||||
"test_opensearch/test_server_secured/",
|
"test_opensearchpy/test_server_secured/",
|
||||||
"test_opensearch/test_async/test_server/",
|
"test_opensearchpy/test_async/test_server/",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -129,8 +129,8 @@ def run_all(argv=None):
|
|||||||
argv.append(join(test_dir, "test_server_secured"))
|
argv.append(join(test_dir, "test_server_secured"))
|
||||||
ignores.extend(
|
ignores.extend(
|
||||||
[
|
[
|
||||||
"test_opensearch/test_server/",
|
"test_opensearchpy/test_server/",
|
||||||
"test_opensearch/test_async/test_server/",
|
"test_opensearchpy/test_async/test_server/",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
@@ -139,7 +139,7 @@ def run_all(argv=None):
|
|||||||
argv.append(join(test_dir, "test_async/test_server"))
|
argv.append(join(test_dir, "test_async/test_server"))
|
||||||
ignores.extend(
|
ignores.extend(
|
||||||
[
|
[
|
||||||
"test_opensearch/test_server_secured/",
|
"test_opensearchpy/test_server_secured/",
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
+4
-4
@@ -37,9 +37,9 @@ import pytest
|
|||||||
from mock import patch
|
from mock import patch
|
||||||
from multidict import CIMultiDict
|
from multidict import CIMultiDict
|
||||||
|
|
||||||
from opensearch import AIOHttpConnection, __versionstr__
|
from opensearchpy import AIOHttpConnection, __versionstr__
|
||||||
from opensearch.compat import reraise_exceptions
|
from opensearchpy.compat import reraise_exceptions
|
||||||
from opensearch.exceptions import ConnectionError
|
from opensearchpy.exceptions import ConnectionError
|
||||||
|
|
||||||
pytestmark = pytest.mark.asyncio
|
pytestmark = pytest.mark.asyncio
|
||||||
|
|
||||||
@@ -312,7 +312,7 @@ class TestAIOHttpConnection:
|
|||||||
== str(w[0].message)
|
== str(w[0].message)
|
||||||
)
|
)
|
||||||
|
|
||||||
@patch("opensearch.connection.base.logger")
|
@patch("opensearchpy.connection.base.logger")
|
||||||
async def test_uncompressed_body_logged(self, logger):
|
async def test_uncompressed_body_logged(self, logger):
|
||||||
con = await self._get_mock_connection(connection_params={"http_compress": True})
|
con = await self._get_mock_connection(connection_params={"http_compress": True})
|
||||||
await con.perform_request("GET", "/", body=b'{"example": "body"}')
|
await con.perform_request("GET", "/", body=b'{"example": "body"}')
|
||||||
+4
-4
@@ -28,8 +28,8 @@ import asyncio
|
|||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
import opensearch
|
import opensearchpy
|
||||||
from opensearch.helpers.test import CA_CERTS, OPENSEARCH_URL
|
from opensearchpy.helpers.test import CA_CERTS, OPENSEARCH_URL
|
||||||
|
|
||||||
from ...utils import wipe_cluster
|
from ...utils import wipe_cluster
|
||||||
|
|
||||||
@@ -40,11 +40,11 @@ pytestmark = pytest.mark.asyncio
|
|||||||
async def async_client():
|
async def async_client():
|
||||||
client = None
|
client = None
|
||||||
try:
|
try:
|
||||||
if not hasattr(opensearch, "AsyncOpenSearch"):
|
if not hasattr(opensearchpy, "AsyncOpenSearch"):
|
||||||
pytest.skip("test requires 'AsyncOpenSearch'")
|
pytest.skip("test requires 'AsyncOpenSearch'")
|
||||||
|
|
||||||
kw = {"timeout": 3, "ca_certs": CA_CERTS}
|
kw = {"timeout": 3, "ca_certs": CA_CERTS}
|
||||||
client = opensearch.AsyncOpenSearch(OPENSEARCH_URL, **kw)
|
client = opensearchpy.AsyncOpenSearch(OPENSEARCH_URL, **kw)
|
||||||
|
|
||||||
# wait for yellow status
|
# wait for yellow status
|
||||||
for _ in range(100):
|
for _ in range(100):
|
||||||
+1
-1
@@ -58,7 +58,7 @@ class TestYarlMissing:
|
|||||||
self, async_client, monkeypatch
|
self, async_client, monkeypatch
|
||||||
):
|
):
|
||||||
# This is a defensive test case for if aiohttp suddenly stops using yarl.
|
# This is a defensive test case for if aiohttp suddenly stops using yarl.
|
||||||
from opensearch._async import http_aiohttp
|
from opensearchpy._async import http_aiohttp
|
||||||
|
|
||||||
monkeypatch.setattr(http_aiohttp, "yarl", False)
|
monkeypatch.setattr(http_aiohttp, "yarl", False)
|
||||||
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user