php-elasticsearch croll分页

1,分页

   

$page = 1;
$size = 10;
$es_search = [
"scroll"=>"1m",
"size"=>$size,
"index"=>"index_search",
"from"=>$page*$size,
"body"=>[]
];
$client = ClientBuilder::create()->build();
$es = $client->search($es_search);
$scroll_id = $es['_scroll_id'];
if($page == 1){
return $es['hits']['hits'];//首页
}

$i = 1;
while( $i < $page ){
$response = $client->scroll(['scroll_id'=>$scroll_id,'scroll'=>'1m']);
if(count($response['hits']['hits'])>0){
$scroll_id = $response['_scroll_id'];
}else{
break;
}
$i++;
}
return $response['hits']['hits'];
posted @ 2019-09-18 18:19  尚真  阅读(361)  评论(0)    收藏  举报