Helpers.parallel_bulk in Python not working?

Hi,

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):

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

Hope this helps.

8 Likes