Skip to content

Update helpers.rst to include information about how to use parallel_bulk #965

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 31, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions docs/helpers.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,23 @@ document is like ``{"word": "<myword>"}``.
For a more complete and complex example please take a look at
https://github.com/elastic/elasticsearch-py/blob/master/example/load.py#L76-L130

The :meth:`~elasticsearch.Elasticsearch.parallel_bulk` api is a wrapper around the :meth:`~elasticsearch.Elasticsearch.bulk` api to provide threading. :meth:`~elasticsearch.Elasticsearch.parallel_bulk` returns a generator which must be consumed to produce results.

To see the results use:

.. code:: python

for success, info in parallel_bulk(...):
if not success:
print('A document failed:', info)

If you don't care about the results, you can use deque from collections:

.. code:: python

from collections import deque
deque(parallel_bulk(...), maxlen=0)

.. note::

When reading raw json strings from a file, you can also pass them in
Expand Down