jolicode / jolicode/elastically

[Feature] purgeOldIndices raise exception if closing indices isn't allowed on the cluster

Open
#49 0 comments 1 reaction 0 assignees View on GitHub
help wanted
Dominant language
PHP
Stars
257
Forks
43
Avg merge
38m
Merged PRs (30d)
1

Description

The [Close API doc](https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-close.html) 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.enable` to `false`. The default is `true`.

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 `true` before trying to close it (if `false` then just continue)
- add a way to set `cluster.indices.close.enable` to `true` before 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](https://www.elastic.co/guide/en/elasticsearch/reference/current/cluster-update-settings.html) gives the following order of precedence:
>1. transient cluster settings
>2. persistent cluster settings
>3. settings in the `elasticsearch.yml` configuration file.

Then my actual code to do this force mode on my side
```php
$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);
}
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.