# Watcher: how to dynamically calculate indices

**URL:** <https://discuss.elastic.co/t/watcher-how-to-dynamically-calculate-indices/48732>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [April 28, 2016, 8:36pm UTC](https://discuss.elastic.co/t/watcher-how-to-dynamically-calculate-indices/48732 "2016-04-28T20:36:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![eeivin](https://avatars.discourse-cdn.com/v4/letter/e/90ced4/32.png) [@eeivin](https://discuss.elastic.co/u/eeivin)\
**Post date:** [April 28, 2016, 8:36pm UTC](https://discuss.elastic.co/t/watcher-how-to-dynamically-calculate-indices/48732/1 "2016-04-28T20:36:50Z")

</div>

Is there a way to use scripts/template to calculated indices dynamically, to achieve the following?  
"indices" : [ "logstash-2016.{{Calendar.getInstance().MONTH}}.{{Calendar.getInstance().DAY\_OF\_MONTH}}

Here is some background  
o A watcher is used to monitor application logs for critical errors  
o A new index is created daily (older index indexes are periodically deleted). Indexes are named as follows: logstash-YYYY-MM.DD  
o The watcher is configured to run every 15 min and to search for critical errors that occurred in the last 15 min "range": {"@timestamp": {"gt": "now-15m"}  
o Currently the indices for the watcher are specified using wildcard as follows: "indices" : ["logstash-2016._._"]

Thank you for your help,  
Eric

---

<div class="post-metadata">

**Author:** ![skearns](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/skearns/32/125945_2.png) [@skearns](https://discuss.elastic.co/u/skearns)\
**Post date:** [April 28, 2016, 8:53pm UTC](https://discuss.elastic.co/t/watcher-how-to-dynamically-calculate-indices/48732/2 "2016-04-28T20:53:49Z")

</div>

Hi Eric,

When using Watcher to query Elasticsearch, you should be able to use [index name date math](https://www.elastic.co/guide/en/elasticsearch/reference/current/date-math-index-names.html).

Fun fact: that feature was originally developed for Watcher 🙂

Thanks,  
Steve

---

<div class="post-metadata">

**Author:** ![eeivin](https://avatars.discourse-cdn.com/v4/letter/e/90ced4/32.png) [@eeivin](https://discuss.elastic.co/u/eeivin)\
**Post date:** [April 29, 2016, 4:14pm UTC](https://discuss.elastic.co/t/watcher-how-to-dynamically-calculate-indices/48732/3 "2016-04-29T16:14:24Z")

</div>

That is exactly what I was looking for.

Thank you for your help,  
Eric

---

<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 6, 2017, 1:45pm UTC](https://discuss.elastic.co/t/watcher-how-to-dynamically-calculate-indices/48732/4 "2017-07-06T13:45:46Z")

</div>


