python - 有没有办法将 tqdm(进度条)与 ElasticSearch 批量上传一起使用?
问题描述
如标题所述,我正在寻找一种很好的视觉方式来检查我的 ES 客户端上传
我可以使用:
for i in tqdm(<my_docs>):
es_client.create(...)
但我想使用推荐的(ES)方式:
helpers.bulk(...) <- how to add tqdm here?
解决方案
是的,但是bulk
您需要使用 ,而不是使用streaming_bulk
。不像bulk
,它最终只返回最终结果,streaming_bulk
每次操作都会产生结果。有了这个,我们可以tqdm
在每次操作后更新。
代码看起来或多或少是这样的:
# Setup the client
client = Elasticsearch()
# Set total number of documents
number_of_docs = 100
progress = tqdm.tqdm(unit="docs", total=number_of_docs)
successes = 0
for ok, action in streaming_bulk(
client=client, index="my-index", actions=<your_generator_here>
):
progress.update(1)
successes += ok
print(f"Indexed {successes}/{number_of_docs} documents")
推荐阅读
- php - CodeIgniter 3:在 MY_Model 上加载库
- typescript - TypeScript 中的 mixin 和交集类型有什么区别?
- nlp - 使用预训练的词嵌入会加速 Pytorch 中的模型训练吗?另外,如果数据集中的某些词不在嵌入中怎么办?
- matlab - 如何在 MATLAB 中计算后立即访问元素?
- java - Spring Boot:org.springframework.beans.factory.UnsatisfiedDependencyException
- c# - 如何从字符串中解析特定的函数名及其参数?
- python - 从列表中查找最高整数和对应字符串
- laravel - 如何使用环境变量作为其他环境变量的参考?
- apache-spark - 如何在火花中读取pdf文件
- javascript - 如何使用 Angular 6 ngFor 将子元素显示为父元素