背景:使用PHP7查询Elasticsearch7的数据
错误1:Elasticsearch 7.0.1 - Trying to create too many scroll contexts. Must be less than or equal to: [500]
原因:在search($params)中设置的timeout时间内,累计生成的scroll_id数超过了最大限制
解决方法:查询scroll以后,删除对应的id,即调用clearScroll方法
代码如下:
$response = $this->client->search($params); // Execute the search
while (isset($response['hits']['hits']) && count($response['hits']['hits']) > 0) {
// **
// 对response内容进行处理
// **
// When done, get the new scroll_id
// You must always refresh your _scroll_id! It can change sometimes
$scroll_id = $response['_scroll_id'];
// Execute a Scroll request and repeat
$response = $this->client->scroll([
'scroll_id' => $scroll_id, //...using our previously obtained _scroll_id
'scroll' => $timeout // and the same timeout window
]
);
}
$this->client->clearScroll(array('scroll_id' => $response['_scroll_id']));
错误1:No search context found for id
原因:ES端的scroll_id失效,一般是1)由于PHP中的search($params)设置的size设置过大,导致数据未能及时处理。2)对response数据的处理超时
解决方法:减小size设置,或 排查response的处理耗时