_update_by_query + 脚本无法正常工作,错误:试图创建太多滚动上下文

问题描述

Elasticsearch 版本:7.6.2

JVM:13.0.2

操作系统版本:centeros7

这是我的代码

POST  recommend_index/_update_by_query  

{
               "script": {
            "source": "ctx._source.rec_doctor_id = 1"
        },"query": {
                    "bool": {
                "must": [{
                            "terms": {
                                "id": ["22222"]
                            }
                             }]
                    }
                           }
         }

这段代码没有正确返回结果,错误信息是

{
  "error": {
    "root_cause": [
      {
        "type": "exception","reason": "Trying to create too many scroll contexts. Must be less than or equal to: [5000]. This limit can be set by changing the [search.max_open_scroll_context] setting."
      }
    ],"type": "search_phase_execution_exception","reason": "Partial shards failure","phase": "query","grouped": true,"Failed_shards": [
      {
        "shard": 1,"index": "recommend_index","node": "XXX","reason": {
          "type": "exception","reason": "Trying to create too many scroll contexts. Must be less than or equal to: [5000]. This limit can be set by changing the [search.max_open_scroll_context] setting."
        }
      }
    ]
  },"status": 500
}

我确定当前滚动为 0

当我用_UPDATE替换_UPDATE_BY_QUERY时,它会正常更新

ES从上周五开始就没有任何变化,突然报错

未对 ES 服务器进行任何配置更改

解决方法

后续: 我将 search.max_open_scroll_context 参数设置为 5000 并发现与它无关。 我查了 7.6.2 版本,发现有人和我有同样的问题。链接在这个 这里#71354 #56202 估计是滚动触发了7.6.2的bug。我没升级就重启了集群节点,发现成功了!!