# Watcher action - Dynamic index creation

**URL:** <https://discuss.elastic.co/t/watcher-action-dynamic-index-creation/101759>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-alerting\
**Created:** [September 25, 2017, 9:17pm UTC](https://discuss.elastic.co/t/watcher-action-dynamic-index-creation/101759 "2017-09-25T21:17:13Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![santhosh](https://avatars.discourse-cdn.com/v4/letter/s/f07891/32.png) [@santhosh](https://discuss.elastic.co/u/santhosh)\
**Post date:** [September 25, 2017, 9:17pm UTC](https://discuss.elastic.co/t/watcher-action-dynamic-index-creation/101759/1 "2017-09-25T21:17:13Z")

</div>

I have a watcher that sends output to another index named "newindex". How can I set the dynamic value to target index such as date? Following approach doesn't work.

```
"actions": {
    "index_payload": {
      "index": {
        "index": "newindex-{now/d}",
        "doc_type": "docType2",
        "execution_time_field": "trigger_event.triggered_time"
      }
    }
  }

```

And it gives following error.

```
"last_execution": {
          "timestamp": "2017-09-25T21:12:46.413Z",
          "successful": false,
          "reason": "InvalidIndexNameException[Invalid index name [newindex-{now/d}], must not contain the following characters [, \", *, \\, <, |, ,, >, /, ?]]"
        }

```

I have even tried with `newindex-%{+YYYY.MM.dd}` too. It too didn't work. Can you please help on how to do it?

---

<div class="post-metadata">

**Author:** ![luke.snyder](https://avatars.discourse-cdn.com/v4/letter/l/a4c791/32.png) [@luke.snyder](https://discuss.elastic.co/u/luke.snyder)\
**Post date:** [September 29, 2017, 3:04pm UTC](https://discuss.elastic.co/t/watcher-action-dynamic-index-creation/101759/2 "2017-09-29T15:04:40Z")

</div>

+1 on this. I am also attempting to do the same thing.

---

<div class="post-metadata">

**Author:** ![spinscale](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/spinscale/32/25011_2.png) [@spinscale](https://discuss.elastic.co/u/spinscale)\
**Post date:** [October 2, 2017, 12:59pm UTC](https://discuss.elastic.co/t/watcher-action-dynamic-index-creation/101759/3 "2017-10-02T12:59:31Z")

</div>

there is a slight glitch in your index syntax. You need to wrap the date math in the `<>` brackets, like `<logstash-{now/d}>`, then it should work.

---

<div class="post-metadata">

**Author:** ![santhosh](https://avatars.discourse-cdn.com/v4/letter/s/f07891/32.png) [@santhosh](https://discuss.elastic.co/u/santhosh)\
**Post date:** [October 4, 2017, 8:39pm UTC](https://discuss.elastic.co/t/watcher-action-dynamic-index-creation/101759/4 "2017-10-04T20:39:37Z")

</div>

It worked. Thanks @spinscale

---

<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 1, 2017, 8:39pm UTC](https://discuss.elastic.co/t/watcher-action-dynamic-index-creation/101759/5 "2017-11-01T20:39:39Z")

</div>

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