elastically
elastically copied to clipboard
[Feature] purgeOldIndices raise exception if closing indices isn't allowed on the cluster
The Close API doc says :
Closed indices consume a significant amount of disk-space which can cause problems in managed environments. Closing indices can be disabled via the cluster settings API by setting
cluster.indices.close.enabletofalse. The default istrue.
Some clusters may have the default value of cluster.indices.close.enable set to false.
Which can produce this kind of exception :
Uncaught Elastica\\Exception\\ResponseException: closing indices is disabled - set [cluster.indices.close.enable: true] to enable it. NOTE: closed indices still consume a significant amount of diskspace
Some ideas:
- check if the closing indices parameter is
truebefore trying to close it (iffalsethen just continue) - add a way to set
cluster.indices.close.enabletotruebefore closing (and reset it to it's previous state after)- either : add a "forceCloseMode" parameter to purgeOldIndices
- or/and : add method to set/unset a setting param
Besides, the Cluster Update Settings API doc gives the following order of precedence:
- transient cluster settings
- persistent cluster settings
- settings in the
elasticsearch.ymlconfiguration file.
Then my actual code to do this force mode on my side
$mycluster = new Cluster($client);
$mysettings = $mycluster->getSettings();
$oldParam = $mysettings->getTransient('cluster.indices.close.enable');
if (true !== $oldParam) {
$mysettings->setTransient('cluster.indices.close.enable', true);
}
$indexBuilder->purgeOldIndices($indexname);
if (true !== $oldParam) {
$mysettings->setTransient('cluster.indices.close.enable', $oldParam);
}