Skip to content

Parallel_bulk helper docs don't explain how to unpack it #964

Closed
@rsmith013

Description

@rsmith013

Parallel bulk returns a generator which has to be unpacked.
This thread https://discuss.elastic.co/t/helpers-parallel-bulk-in-python-not-working/39498 explains the solution. It should be included in the docs.

parallel bulk is a generator, meaning it is lazy and won't produce any results until you start consuming them. The proper way to use it is:

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

If you don't care about the results (which by default you don't have to since any error will cause an exception) you can use the consume function from itertools recipes (https://docs.python.org/2/library/itertools.html#recipes 105):

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions