It looks like you are running into a memory issue. The error you are getting is likely due to the fact that you are trying to load too much data into memory at once. To fix this, you can try increasing the memory limit in your php.ini file. You can also try breaking up your query into smaller chunks and looping through them. For example:
use Elasticsearch\ClientBuilder;
use DataTables;
public function index()
{
$hosts = ['localhost:9200'];
$client = ClientBuilder::create()->setHosts($hosts)->build();
$data = [];
$offset = 0;
$limit = 1000;
while (true) {
$params = [
'index' => 'data',
'type' => 'long',
'body' => [
'from' => $offset,
'size' => $limit,
'query' => [
'match_all' => new \stdClass(),
],
],
];
$results = $client->search($params);
foreach ($results['hits']['hits'] as $hit) {
$source = $hit['_source'];
$data[] = [
'id' => $hit['_id'],
'area_1' => $source['area_1'],
'area_2' => $source['area_2'],
// repeat for all 25 areas
];
}
if (count($results['hits']['hits']) < $limit) {
break;
}
$offset += $limit;
}
return DataTables::of($data)->make(true);
}
This code will loop through the results in chunks of 1000, so you don't have to load all 14,598 records into memory at once.