# Curator: ignore\_empty\_list & warn\_if\_no\_indices

**URL:** <https://discuss.elastic.co/t/curator-ignore-empty-list-warn-if-no-indices/90998>\
**Category:** Elasticsearch\
**Created:** [June 27, 2017, 4:32pm UTC](https://discuss.elastic.co/t/curator-ignore-empty-list-warn-if-no-indices/90998 "2017-06-27T16:32:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sean1e](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sean1e/32/19108_2.png) [@Sean1e](https://discuss.elastic.co/u/Sean1e)\
**Post date:** [June 27, 2017, 4:32pm UTC](https://discuss.elastic.co/t/curator-ignore-empty-list-warn-if-no-indices/90998/1 "2017-06-27T16:32:24Z")

</div>

I am using Curator to add & remove indexes from an alias (curator\_action.yml below). I have ignore\_empty\_list set to True. The indexes in question relate to an application server in our test environment that are used infrequently. Indexes are created with a %Y.%m suffix.

If either the 'add' OR 'remove' section return no indexes I need to set warn\_if\_no\_indices to **True** to have Curator run successfully.  
If both the 'add' AND 'remove' sections return no indexes I need to set warn\_if\_no\_indices to **False** to have Curator run successfully.

I realize that I can create 2 seperate actions, one containing the 'add' and the second action containing the remove. (Your reply to this ticket: [Curator Alias Add not working if Remove list is empty](https://discuss.elastic.co/t/curator-alias-add-not-working-if-remove-list-is-empty/73549))

Is there any way to have Curator run successfully given the 2 scenarios above?

It appears to me that creating 2 seperate actions is the only option when working with indexes where either or both of the add & remove sections can be empty as there does not appear to be a combination of settings that will cater for all scenarios (either or both of the add & remove sections can be empty).

I'm also not sure (anymore - I thought I knew what ignore means) what the object of the ignore\_empty\_list option is ....

**curator\_action.yml**

```
action: alias
description: Alias indices
options:
  disable_action: True
  ignore_empty_list: True
  name: MyIndex-historical
  warn_if_no_indices: True
add:
  filters:
  - filtertype: pattern
    kind: prefix
    value: idx_MyIndex-
    exclude:
  - filtertype: period
    source: name
    range_from: -3
    range_to: -2
    timestring: '%Y.%m'
    unit: months
    week_starts_on: monday
remove:
  filters:
  - filtertype: pattern
    kind: prefix
    value: idx_MyIndex-
  - filtertype: period
    source: name
    range_from: -7
    range_to: -4
    timestring: '%Y.%m'
    unit: months
    week_starts_on: monday
```

---

<div class="post-metadata">

**Author:** ![theuntergeek](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/theuntergeek/32/44961_2.png) [@theuntergeek](https://discuss.elastic.co/u/theuntergeek)\
**Post date:** [June 27, 2017, 5:47pm UTC](https://discuss.elastic.co/t/curator-ignore-empty-list-warn-if-no-indices/90998/2 "2017-06-27T17:47:10Z")

</div>

Sorry you're having a hard time. You seem to be in between a rock and a hard place with this. What you're trying to do, however, is not clean. Elasticsearch will return an error if you attempt to make an update alias API call without a `body` in it. The `body` contains the `add` and `remove` sections, and if there are no indices in both the `add` _and_ `remove` sections, that will result in an exception. Accordingly, Curator cannot make an API call to Elasticsearch without something in it, so _Curator_ raises its own exception, rather than send nothing to Elasticsearch and catch _that_ exception. There is light at the end of the tunnel for your use case, however. Let me explain what's going on in the code and why, before explaining that part.

> [@Sean1e](#):
>
> I'm also not sure (anymore - I thought I knew what ignore means) what the object of the ignore\_empty\_list option is ....

The `alias` action is special. The `ignore_empty_list` option only exists to catch a particular kind of exception, which is that the entire action failed with a `NoIndices` exception, with the test being in the [CLI code](https://github.com/elastic/curator/blob/v5.1.1/curator/cli.py#L178-L183), rather than in the action. For _only_ the alias action, setting `warn_if_no_indices: True` effectively [causes Curator to not raise the `NoIndices` exception](https://github.com/elastic/curator/blob/v5.1.1/curator/actions.py#L49-L59). As a result, for the alias action, `ignore_empty_list` is useless if you've set `warn_if_no_indices: True`.

Here's what's going on under the hood.

1. Because `warn_if_no_indices` is set to `True`, the `warn_if_no_indices` checks [here](https://github.com/elastic/curator/blob/v5.1.1/curator/actions.py#L51) and [here](https://github.com/elastic/curator/blob/v5.1.1/curator/actions.py#L83) mean that Curator gets the go-ahead to attempt the alias update API call, even when there are no indices selected.

2. Curator will attempt [`do_action`](https://github.com/elastic/curator/blob/v5.1.1/curator/actions.py#L143-L152), which will generate the `body` on demand, [here](https://github.com/elastic/curator/blob/v5.1.1/curator/actions.py#L148) and [here](https://github.com/elastic/curator/blob/v5.1.1/curator/actions.py#L150).

3. When _both_ the `add` and the `remove` filters result in empty lists, there is nothing in [`self.actions`](https://github.com/elastic/curator/blob/v5.1.1/curator/actions.py#L116), which results in an [`ActionError` exception](https://github.com/elastic/curator/blob/v5.1.1/curator/actions.py#L117) being raised.

This is what Curator should be doing. It's telling you that you hit an unrecoverable exception—that it cannot make an API call with no adds or removes in it. However, you want Curator to ignore this exception, because you, the operator, know that this might happen. The way to do so is to set `continue_if_exception: True` in your options, as you want to bypass this legitimate exception.

---

<div class="post-metadata">

**Author:** ![Sean1e](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sean1e/32/19108_2.png) [@Sean1e](https://discuss.elastic.co/u/Sean1e)\
**Post date:** [June 28, 2017, 9:17am UTC](https://discuss.elastic.co/t/curator-ignore-empty-list-warn-if-no-indices/90998/3 "2017-06-28T09:17:44Z")

</div>

Aaron,

This to say thanks for a prompt response with a detailed & knowledgeable answer.

Cheers - Thanks again!  
Sean

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 26, 2017, 9:17am UTC](https://discuss.elastic.co/t/curator-ignore-empty-list-warn-if-no-indices/90998/4 "2017-07-26T09:17:48Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
