I’m trying to make a piece of code that will be responsible for deleting an indexed file from the elasticsearch index, I pass with the indexed file md5(file name), to the id value. It is necessary to make sure that when deleting a file from a folder, the deletion code by id (md5) is executed. I wrote part of the script, but I understand that it is incorrect because if there is no file, then md5 will not be created, please help)
<?php
$path = __DIR__ . ("/uploads/Арне.pptx");
$filename = basename($path);
$md5 = md5_file($path);
print($md5); //Передаю переменную md5 в 'id' индексации elasticsearch
//echo 'MD5-хеш файла ' . $filename . ': ' . md5_file($path);
if (empty(md5_file($path))) {//Провожу проверку, если md5 не совпадает с именем файла в папке
$params = [ //Произвожу удаление индекса из ES
'index' => 'bower',
'id' => $md5
];
$respose = $client->delete($params);
} else {
echo '' . ' есть, файл существует';
}
2
Answers
You can close the topic, the issue is resolved. Solved the problem: Iterating over the array in the uploads folder, and iterating over the elasticsearch array id, then used array_diff, compared the arrays to exclude files that are not in the uploads folder, but they were in the elasticsearch index
You need to use the delete index method instead of deleting documents: