# Can I dynamically specify indices to search?

**URL:** <https://discuss.elastic.co/t/can-i-dynamically-specify-indices-to-search/69068>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [December 14, 2016, 6:21pm UTC](https://discuss.elastic.co/t/can-i-dynamically-specify-indices-to-search/69068 "2016-12-14T18:21:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon12945697](https://avatars.discourse-cdn.com/v4/letter/a/74df32/32.png) [@anon12945697](https://discuss.elastic.co/u/anon12945697)\
**Post date:** [December 14, 2016, 6:21pm UTC](https://discuss.elastic.co/t/can-i-dynamically-specify-indices-to-search/69068/1 "2016-12-14T18:21:24Z")

</div>

Hi there,

I have a question for Watcher. Can I dynamically specify indices to search?

Example:  
I have multiple logs, named in the format: "log-yyyy-mm-dd", like "log-2016-12-14".  
I have a watch run every 5 mins, searching for exceptions in log indices in last 30 mins.  
Currently, my watch search all indices. It is kind of wasting resource. I would like to specify the indices, to use only today and yesterday's indices. It means I need to dynamically specify indices to search.

How can I do that?

Thanks,

Da

---

<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:** [December 14, 2016, 8:48pm UTC](https://discuss.elastic.co/t/can-i-dynamically-specify-indices-to-search/69068/2 "2016-12-14T20:48:37Z")

</div>

Yes, you can use index date math[1] to specify an index.

[1] [https://www.elastic.co/guide/en/elasticsearch/reference/current/date-math-index-names.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/date-math-index-names.html)

---

<div class="post-metadata">

**Author:** ![anon12945697](https://avatars.discourse-cdn.com/v4/letter/a/74df32/32.png) [@anon12945697](https://discuss.elastic.co/u/anon12945697)\
**Post date:** [December 15, 2016, 6:57pm UTC](https://discuss.elastic.co/t/can-i-dynamically-specify-indices-to-search/69068/3 "2016-12-15T18:57:09Z")

</div>

That's cool! I'll give it a try 🙂

---

<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:** [January 12, 2017, 6:57pm UTC](https://discuss.elastic.co/t/can-i-dynamically-specify-indices-to-search/69068/4 "2017-01-12T18:57:23Z")

</div>

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