As the heading states, I’m looking for a nice visual way to check my ES client upload
I can either use:
JavaScript
x
3
1
for i in tqdm(<my_docs>):
2
es_client.create( )
3
but I want to use the recommended (by ES) way:
JavaScript
1
2
1
helpers.bulk( ) <- how to add tqdm here?
2
Advertisement
Answer
Yes, but instead of using bulk
, you need to use streaming_bulk
. Unlike bulk
, which only returns the final result in the end, streaming_bulk
yields results per action. With this, we can update tqdm
after each action.
The code looks more or less like this:
JavaScript
1
17
17
1
# Setup the client
2
client = Elasticsearch()
3
4
# Set total number of documents
5
number_of_docs = 100
6
7
progress = tqdm.tqdm(unit="docs", total=number_of_docs)
8
successes = 0
9
10
for ok, action in streaming_bulk(
11
client=client, index="my-index", actions=<your_generator_here>
12
):
13
progress.update(1)
14
successes += ok
15
16
print(f"Indexed {successes}/{number_of_docs} documents")
17