Loading

Elasticsearch scroll常见错误

最近使用es嘎嘎报错:

Trying to create too many scroll contexts. Must be less than or equal to: [500]

  • 原因:在search()中设置的timeout时间内,累计生成的scroll_id数超过了最大限制
  • 解决方法:查询scroll以后,删除对应的id,即调用clearScroll方法
            //搜索查询
            $response = $this->client->search($params);
            while (isset($response['hits']['hits']) && count($response['hits']['hits']) > 0) {
     
                //对response内容进行处理
                $scroll_id = $response['_scroll_id'];
                // Execute a Scroll request and repeat
                $response = $this->client->scroll([
                     'scroll_id' => $scroll_id,      //游标id
                     'scroll'    => $timeout         //超时时间
                ]);
     
            }
            //清除scroll_id
            $this->client->clearScroll(array('scroll_id' => $response['_scroll_id']));
posted @ 2023-09-06 23:17  Carvers  阅读(1235)  评论(0)    收藏  举报