py-es-bulk
A simple wrapper around the Python elasticsearch client put_template(), streaming_bulk(), and parallel_bulk() helper APIs with robust error handling.
This library is designed to work across various versions of the
elasticsearch Python module and of the Elasticsearch server, by
dynamically identifying the module used to create the Elasticsearch object.
These names are available for import:
-
put_templatePush a document template to the server using a specified Elasticsearch object. This module will determine whether a template document of the same name and version already exists, and PUT the new template if not.
Args:
es: An instance of theElasticsearchclass.name: The name of the template.mapping_name: The name of the mapping used in the template.body: The payload body of the template.
Returns: A tuple (start_time, end_time, retry_count, error_keys)
-
streaming_bulkPush multiple source documents to Elasticsearch indices, using proper error handling and retry logic.
Args:
- 'es': An instance of the
Elasticsearchclass. actions: An iterable of Elasticsearch action records (passed directly to Elasticsearch).errorsfp: A file pointer where HTTP 400 errors are logged.logger: ALoggerobject where messages can be logged.
Returns: A tuple (start_time, end_time, successfully_indexed, duplicate, failed, retry_count).
- 'es': An instance of the
-
parallel_bulkPush multiple source documents to Elasticsearch indices in parallel across multiple threads, using proper error handling and retry logic.
Args:
es: An instance of theElasticsearchclass.actions: An iterable of Elasticsearch action records (passed directly to Elasticsearch)errorsfp: A file pointer where HTTP 400 errors are logged.logger: ALoggerobject where messages can be logged.chunk_size=10000000: Number of docs sent in one chunk to Elasticsearch.max_chunk_bytes=104857600: The maximum size of a request.thread_count=8: The size of the thread pool to use.queue_size=4: The size of the task queue between the controller and processing threads.
Returns: A tuple (start_time, end_time, successfully_indexed, duplicate, failed, retry_count)
-
TemplateExceptionThis exception is raised by put_template when a template document does not contain the required version metadata (
{"_meta": {"version": <integer>}}); or, when multiple template documents are included in a single call to put_template, if the versions of those documents are not all identical.
Unit testing support
The pyesbulk package attempts to dynamically determine the
Python module used to produce the Elasticsearch object that's passed in to pyesbulk methods. This is necessary in order to properly resolve exception classes for the error handling and retry logic.
However, unit tests often work with mocked objects which
won't have "real" Python package structure, and the dynamic
module recognition algorithm may fail. When this happens,
pyesbulk will attempt to import elasticsearch. If that's not correct (e.g., if you're using elasticsearch1
or elasticsearch5), you can override the automatic search
by including a force_elastic_search_module property on
your mocked Elasticsearch object.
For example,
class MockElasticsearch:
def __init__(self):
self.force_elastic_search_module = "elasticsearch5"
or
es = MockElasticSearch()
es.force_elastic_search_module = "elasticsearch1"
See also https://pypi.org/project/pyesbulk/.
Metadata
Release files for pyesbulk 2.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyesbulk-2.1.1-py3-none-any.whl | Python 3 | none | any | Details for pyesbulk-2.1.1-py3-none-any.whl |
Release files / pyesbulk-2.1.1-py3-none-any.whl
| Download URL | pyesbulk-2.1.1-py3-none-any.whl |
|---|---|
| Size | 21.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c693635bd9c4600331a98f8c4b6e91f26e92ea24eda64268e9c963b10648b98c
|
|
BLAKE2b-256 checksum How to use checksums |
02bf11655609b9f1426ee14436ad19ef6169f59496661ff5bbbddefc352b19f9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.6.0 requests/2.20.0 setuptools/50.2.0 requests-toolbelt/0.9.1 tqdm/4.50.2 CPython/3.6.8
|
Security for pyesbulk 2.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.