【问题标题】:Python ElasticSearch updating field on multiple documents without script compilation rate limit没有脚本编译速率限制的多个文档上的 Python ElasticSearch 更新字段
【发布时间】:2022-01-13 00:06:16
【问题描述】:

我正在使用

from elasticsearch import Elasticsearch
from elasticsearch_dsl import UpdateByQuery
UpdateByQuery(index=index).using(es_client).query("match", id=<my_obj_id>)\
            .script(source=f"ctx._source.view_count=12345")

更新我的 ElasticSearch 文档之一上的 view_count 字段。

问题出在生产中,有很多文档需要更新,我得到了

TransportError(500, 'general_script_exception', '[script] Too many dynamic script compilations within, max: [75/5m]; please use indexed, or scripts with parameters instead; this limit can be changed by the [script.context.update.max_compilations_rate] setting')

我不确定增加限制是否是一个长期的解决方案。但是我不知道如何一次对多个文档进行批量更新以避免这么多调用?

【问题讨论】:

    标签: python elasticsearch


    【解决方案1】:

    您可以使用bulk API,它允许一次更新多个文档(参见此处的示例)。

    通常,您应该尽可能尝试使用“doc”更新而不是“script”。

    【讨论】:

      猜你喜欢
      • 2016-08-11
      • 1970-01-01
      • 1970-01-01
      • 2020-02-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-14
      • 1970-01-01
      相关资源
      最近更新 更多