# Use greedy regexes in Curator filter

**URL:** <https://discuss.elastic.co/t/use-greedy-regexes-in-curator-filter/154200>\
**Category:** Elasticsearch\
**Created:** [October 26, 2018, 12:41pm UTC](https://discuss.elastic.co/t/use-greedy-regexes-in-curator-filter/154200 "2018-10-26T12:41:06Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![dr01](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dr01/32/8482_2.png) [@dr01](https://discuss.elastic.co/u/dr01)\
**Post date:** [October 26, 2018, 12:41pm UTC](https://discuss.elastic.co/t/use-greedy-regexes-in-curator-filter/154200/1 "2018-10-26T12:41:06Z")

</div>

I have set up Curator to delete old indexes via this filter:

```
(...)
filters:
- filtertype: pattern
  kind: regex
  value: '^xyz-us-(prod|preprod)-(.*)-'
  exclude:
- filtertype: age
  source: name
  direction: older
  timestring: '%Y.%m.%d'
  unit: days
  unit_count: 7
  exclude:
(...)

```

However, I realized that Curator uses non-greedy regexes, because this filter catches the index _xyz-us-prod-foo-2018.10.11_ but not _xyz-us-prod-foo-bar-2018.10.11_.

How can I modify the filter to catch both indexes?

Thanks in advance.

---

<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:** [October 26, 2018, 1:42pm UTC](https://discuss.elastic.co/t/use-greedy-regexes-in-curator-filter/154200/2 "2018-10-26T13:42:59Z")

</div>

You shouldn't need the second set of parenthesis.

Also, have you tried fully anchoring the end of the line? This example is untested, but should work.

```auto
'^xyz-us-(prod|preprod)-.*-\d{4}\.\d{2}\.\d{2}$'

```

Being more precise with this should allow the `.*` to truly capture anything between `(prod|preprod)` and the date.

---

<div class="post-metadata">

**Author:** ![dr01](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dr01/32/8482_2.png) [@dr01](https://discuss.elastic.co/u/dr01)\
**Post date:** [October 29, 2018, 10:05am UTC](https://discuss.elastic.co/t/use-greedy-regexes-in-curator-filter/154200/3 "2018-10-29T10:05:16Z")

</div>

Thanks for your answer. I've tried it but the change doesn't have any effect.

---

<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:** [October 30, 2018, 1:05am UTC](https://discuss.elastic.co/t/use-greedy-regexes-in-curator-filter/154200/4 "2018-10-30T01:05:50Z")

</div>

Seems to work just fine for me. With this config:

```auto
---
actions:
  1:
    action: delete_indices
    filters:
    - filtertype: pattern
      kind: regex
      value: '^xyz-us-(prod|preprod)-.*-\d{4}\.\d{2}\.\d{2}$'
      exclude:
    - filtertype: age
      source: name
      direction: older
      timestring: '%Y.%m.%d'
      unit: days
      unit_count: 7

```

I created these indices:

```auto
PUT xyz-us-prod-foo-2018.10.11
PUT xyz-us-prod-foo-bar-2018.10.11

```

and it matched both of them:

```auto
2018-10-29 20:02:29,091 DEBUG curator.indexlist filter_by_regex:425 Filtering indices by regex
2018-10-29 20:02:29,091 DEBUG curator.indexlist empty_list_check:225 Checking for empty list
2018-10-29 20:02:29,091 DEBUG curator.indexlist working_list:236 Generating working list of indices
2018-10-29 20:02:29,091 DEBUG curator.indexlist filter_by_regex:446 Filter by regex: Index: xyz-us-prod-foo-2018.10.11
2018-10-29 20:02:29,091 DEBUG curator.indexlist __actionable:35 Index xyz-us-prod-foo-2018.10.11 is actionable and remains in the list.
2018-10-29 20:02:29,091 DEBUG curator.indexlist filter_by_regex:446 Filter by regex: Index: xyz-us-prod-foo-bar-2018.10.11
2018-10-29 20:02:29,092 DEBUG curator.indexlist __actionable:35 Index xyz-us-prod-foo-bar-2018.10.11 is actionable and remains in the list.
2018-10-29 20:02:29,092 DEBUG curator.indexlist iterate_filters:1185 Post-instance: ['xyz-us-prod-foo-2018.10.11', 'xyz-us-prod-foo-bar-2018.10.11']
...
2018-10-29 20:02:29,097 INFO curator.utils show_dry_run:918 DRY-RUN MODE. No changes will be made.
2018-10-29 20:02:29,097 INFO curator.utils show_dry_run:921 (CLOSED) indices may be shown that may not be acted on by action "delete_indices".
2018-10-29 20:02:29,097 INFO curator.utils show_dry_run:928 DRY-RUN: delete_indices: xyz-us-prod-foo-2018.10.11 with arguments: {}
2018-10-29 20:02:29,098 INFO curator.utils show_dry_run:928 DRY-RUN: delete_indices: xyz-us-prod-foo-bar-2018.10.11 with arguments: {}
2018-10-29 20:02:29,098 INFO curator.cli run:196 Action ID: 1, "delete_indices" completed.
2018-10-29 20:02:29,098 INFO curator.cli run:197 Job completed.

```

---

<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:** [October 30, 2018, 1:09am UTC](https://discuss.elastic.co/t/use-greedy-regexes-in-curator-filter/154200/5 "2018-10-30T01:09:49Z")

</div>

For good measure, I added these two indices:

```auto
PUT xyz-us-preprod-foo-2018.10.12
PUT xyz-us-preprod-foo-bar-2018.10.12

```

and ran it again. It still works with both patterns:

```auto
2018-10-29 20:08:28,120 INFO curator.utils show_dry_run:928 DRY-RUN: delete_indices: xyz-us-preprod-foo-2018.10.12 with arguments: {}
2018-10-29 20:08:28,120 INFO curator.utils show_dry_run:928 DRY-RUN: delete_indices: xyz-us-preprod-foo-bar-2018.10.12 with arguments: {}
2018-10-29 20:08:28,120 INFO curator.utils show_dry_run:928 DRY-RUN: delete_indices: xyz-us-prod-foo-2018.10.11 with arguments: {}
2018-10-29 20:08:28,120 INFO curator.utils show_dry_run:928 DRY-RUN: delete_indices: xyz-us-prod-foo-bar-2018.10.11 with arguments: {}

```

---

<div class="post-metadata">

**Author:** ![dr01](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dr01/32/8482_2.png) [@dr01](https://discuss.elastic.co/u/dr01)\
**Post date:** [October 31, 2018, 9:34am UTC](https://discuss.elastic.co/t/use-greedy-regexes-in-curator-filter/154200/6 "2018-10-31T09:34:35Z")

</div>

Thanks, it appears to work now. I probably made a mistake before.

One question: how does Curator manage to find the _timestring_ in _value_ ? Does it automatically search for it at the end of the string _value_ ?

---

<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:** [October 31, 2018, 2:58pm UTC](https://discuss.elastic.co/t/use-greedy-regexes-in-curator-filter/154200/7 "2018-10-31T14:58:35Z")

</div>

Nope. It’s pretty much `^.*(\d{4}\.\d{2}\.\d{2}).*$` (or whatever your provided `timestring` extrapolates to).

---

<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:** [November 28, 2018, 2:58pm UTC](https://discuss.elastic.co/t/use-greedy-regexes-in-curator-filter/154200/8 "2018-11-28T14:58:51Z")

</div>

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