【问题标题】:How to handle Transport error in elastic search python client?如何处理弹性搜索 python 客户端中的传输错误?
【发布时间】:2020-11-24 13:56:06
【问题描述】:

我正在将 pandas 数据帧上传到弹性(使用 elasticsearch==6.3.1),如果数据帧大小小于 100MB,它可以正常工作,我正在使用来自 How to export pandas data to elasticsearch? 的解决方案

def rec_to_actions(df):
    for record in df.to_dict(orient="records"):
        yield ('{ "index" : { "_index" : "%s", "_type" : "%s" }}'% (INDEX, TYPE))
        yield (json.dumps(record, default=int))
from elasticsearch import Elasticsearch
e = Elasticsearch([{'host': 'localhost', 'port': 9200}])
r = e.bulk(rec_to_actions(df))

这很完美,但是对于超过 100MB 的数据帧,它会引发传输错误

raise HTTP_EXCEPTIONS.get(status_code, TransportError)(status_code, error_message, additional_info)
TransportError: TransportError(413, '')

如何处理? 我尝试在 elasticsearch.yml 文件中设置 http.max_content_length: 350mb,但仍然出现错误。

还有一个问题是如何在上述函数中添加时间戳字段?

【问题讨论】:

  • 您绝对应该分几批发送您的数据帧

标签: python pandas elasticsearch


【解决方案1】:

您可以分批发送或使用并行批量发送,例如:

from elasticsearch import helpers
results = list(helpers.parallel_bulk(e, generator_fn() , thread_count=2, chunk_size=400, request_timeout=1000, raise_on_error=False))

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-13
    • 1970-01-01
    • 1970-01-01
    • 2020-07-27
    • 2016-11-08
    • 2015-04-20
    • 2017-02-12
    • 1970-01-01
    相关资源
    最近更新 更多