Bulk indexing crashes

How to do just send 1k requests each? As I am looping over my query, how can I loop over it's 1k results, and then loop once again against it's next 1k results? Is my question clear? :frowning:

$query = tep_db_query(" 
// Query giving 500k results
");

$achatsDocs = array();

while($array_collections = tep_db_fetch_array($query)){
	//looping the query


    $achatsDocs[] = new \Elastica\Document('', \Glam\HttpUtils::jsonEncode(
		array(
			// documents
		)
	));
}

$achatsReportType->addDocuments($achatsDocs);
$achatsReportType->getIndex()->refresh();