Streaming bulk consumes actions from the iterable passed in and yields results per action. For non-streaming usecases use bulk()
which is a wrapper around streaming bulk that returns summary information about the bulk operation once the entire input is consumed and sent.
If you specify max_retries
it will also retry any documents that were rejected with a 429
status code. Use retry_on_status
to configure which status codes will be retried. To do this it will wait (by calling time.sleep which will block) for initial_backoff
seconds and then, every subsequent rejection for the same chunk, for double the time every time up to max_backoff
seconds.
client (Elasticsearch) – instance of Elasticsearch
to use
actions (Iterable[bytes | str | Dict[str, Any]]) – iterable containing the actions to be executed
chunk_size (int) – number of docs in one chunk sent to es (default: 500)
max_chunk_bytes (int) – the maximum size of the request in bytes (default: 100MB)
raise_on_error (bool) – raise BulkIndexError
containing errors (as .errors) from the execution of the last chunk when some occur. By default we raise.
raise_on_exception (bool) – if False
then don’t propagate exceptions from call to bulk
and just report the items that failed as failed.
expand_action_callback (Callable[[bytes | str | Dict[str, Any]], Tuple[Dict[str, Any], None | bytes | Dict[str, Any]]]) – callback executed on each action passed in, should return a tuple containing the action line and the data line (None if data line should be omitted).
retry_on_status (int | Collection[int]) – HTTP status code that will trigger a retry. (if None is specified only status 429 will retry).
max_retries (int) – maximum number of times a document will be retried when retry_on_status (defaulting to 429
) is received, set to 0 (default) for no retries
initial_backoff (float) – number of seconds we should wait before the first retry. Any subsequent retries will be powers of initial_backoff * 2**retry_number
max_backoff (float) – maximum number of seconds a retry will wait
yield_ok (bool) – if set to False will skip successful documents in the output
ignore_status (int | Collection[int]) – list of HTTP status code that you want to ignore
client
actions
chunk_size
max_chunk_bytes
raise_on_error
expand_action_callback
raise_on_exception
max_retries
initial_backoff
max_backoff
yield_ok
ignore_status
retry_on_status
span_name (str)
args (Any)
kwargs (Any)
Parallel version of the bulk helper run in multiple threads at once.
client (Elasticsearch) – instance of Elasticsearch
to use
actions (Iterable[bytes | str | Dict[str, Any]]) – iterator containing the actions
thread_count (int) – size of the threadpool to use for the bulk requests
chunk_size (int) – number of docs in one chunk sent to es (default: 500)
max_chunk_bytes (int) – the maximum size of the request in bytes (default: 100MB)
raise_on_error – raise BulkIndexError
containing errors (as .errors) from the execution of the last chunk when some occur. By default we raise.
raise_on_exception – if False
then don’t propagate exceptions from call to bulk
and just report the items that failed as failed.
expand_action_callback (Callable[[bytes | str | Dict[str, Any]], Tuple[Dict[str, Any], None | bytes | Dict[str, Any]]]) – callback executed on each action passed in, should return a tuple containing the action line and the data line (None if data line should be omitted).
queue_size (int) – size of the task queue between the main thread (producing chunks to send) and the processing threads.
ignore_status (int | Collection[int]) – list of HTTP status code that you want to ignore
client
actions
thread_count
chunk_size
max_chunk_bytes
queue_size
expand_action_callback
ignore_status
args (Any)
kwargs (Any)
Helper for the 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 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 options like stats_only
only apply when raise_on_error
is set to False
.
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 streaming_bulk()
helper which will just return the errors and not store them in memory.
client (Elasticsearch) – instance of Elasticsearch
to use
actions (Iterable[bytes | str | Dict[str, Any]]) – iterator containing the actions
stats_only (bool) – if True only report number of successful/failed operations instead of just number of successful and a list of error responses
ignore_status (int | Collection[int]) – list of HTTP status code that you want to ignore
client
actions
stats_only
ignore_status
args (Any)
kwargs (Any)
Any additional keyword arguments will be passed to streaming_bulk()
which is used to execute the operation, see streaming_bulk()
for more accepted parameters.
Simple abstraction on top of the 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 have a standard order in the returned documents (either by score or explicit sort definition) when scrolling, use preserve_order=True
. This may be an expensive operation and will negate the performance benefits of using scan
.
client (Elasticsearch) – instance of Elasticsearch
to use
scroll (str) – Specify how long a consistent view of the index should be maintained for scrolled search
raise_on_error (bool) – raises an exception (ScanError
) if an error is encountered (some shards fail to execute). By default we raise.
preserve_order (bool) – don’t set the search_type
to scan
- this will cause the scroll to paginate with preserving the order. Note that this can be an extremely expensive operation and can easily lead to unpredictable results, use with caution.
size (int) – size (per shard) of the batch send at each iteration.
request_timeout (float | None) – explicit timeout for each call to scan
clear_scroll (bool) – explicitly calls delete on the scroll id via the clear scroll API at the end of the method on completion or error, defaults to true.
scroll_kwargs (MutableMapping[str, Any] | None) – additional kwargs to be passed to scroll()
client
query
scroll
raise_on_error
preserve_order
size
request_timeout
clear_scroll
scroll_kwargs
kwargs (Any)
Any additional keyword arguments will be passed to the initial search()
call:
scan(client, query={"query": {"match": {"title": "python"}}}, index="orders-*", doc_type="books" )
Reindex all documents from one index that satisfy a given query 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 reindex()
api is available as part of elasticsearch 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.
Note
This helper doesn’t transfer mappings, just the data.
client (Elasticsearch) – instance of Elasticsearch
to use (for read if target_client is specified as well)
source_index (str | Collection[str]) – index (or list of indices) to read documents from
target_index (str) – name of the index in the target cluster to populate
target_client (Elasticsearch | None) – optional, is specified will be used for writing (thus enabling reindex between clusters)
chunk_size (int) – number of docs in one chunk sent to es (default: 500)
scroll (str) – Specify how long a consistent view of the index should be maintained for scrolled search
op_type (str | None) – Explicit operation type. Defaults to ‘_index’. Data streams must be set to ‘create’. If not specified, will auto-detect if target_index is a data stream.
scan_kwargs (MutableMapping[str, Any]) – additional kwargs to be passed to scan()
bulk_kwargs (MutableMapping[str, Any]) – additional kwargs to be passed to bulk()
client
source_index
target_index
query
target_client
chunk_size
scroll
op_type
scan_kwargs
bulk_kwargs
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4