我已经设置了策展人,通过这个过滤器删除旧的Elasticsearch索引:
(...)
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:
(...)然而,我意识到策展人使用的是非贪婪的正则表达式,因为这个过滤器捕获的是索引xyz-us-prod-foo-2018.10.11而不是xyz-us-prod-foo-bar-2018.10.11。
如何修改筛选器以捕获两个索引?
发布于 2018-10-30 01:14:57
我在https://discuss.elastic.co/t/use-greedy-regexes-in-curator-filter/154200上给出的答案仍然不错,尽管你无法得到我在那里发布的结果。锚定结束并指定对我有用的日期regex:'^xyz-us-(prod|preprod)-.*-\d{4}\.\d{2}\.\d{2}$'
我创建了这些索引:
PUT xyz-us-prod-foo-2018.10.11
PUT xyz-us-prod-foo-bar-2018.10.11
PUT xyz-us-preprod-foo-2018.10.12
PUT xyz-us-preprod-foo-bar-2018.10.12并使用此配置运行:
---
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结果完全一致:
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: {}发布于 2018-10-27 04:10:33
策展人对Regex引擎的实现使用的是U(非贪婪)标志。
默认情况下,非贪婪的正则表达式会使星型量词变懒,添加"?“非贪婪选项下的修饰符会把它变成贪婪的。
试着添加一个'?‘在正则表达式中的“.*”之后
'^xyz-us-(prod|preprod)-(.*?)-'https://stackoverflow.com/questions/53009073
复制相似问题