# Need help to create current date based Index in LS

**URL:** <https://discuss.elastic.co/t/need-help-to-create-current-date-based-index-in-ls/42834>\
**Category:** Logstash\
**Created:** [February 26, 2016, 9:34am UTC](https://discuss.elastic.co/t/need-help-to-create-current-date-based-index-in-ls/42834 "2016-02-26T09:34:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![vikas\_gopal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vikas_gopal/32/47661_2.png) [@vikas\_gopal](https://discuss.elastic.co/u/vikas_gopal)\
**Post date:** [February 26, 2016, 9:34am UTC](https://discuss.elastic.co/t/need-help-to-create-current-date-based-index-in-ls/42834/1 "2016-02-26T09:34:09Z")

</div>

Hi Experts,

I am aware that I can use following to create date index .  
`index => "prod-%{+YYYY.MM.dd}"` but the problem is, it is picking up logs date rather current date, what I want is to create index on current date basis. Please suggest how I can achieve this ?

Thanks  
VG

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [February 26, 2016, 9:40am UTC](https://discuss.elastic.co/t/need-help-to-create-current-date-based-index-in-ls/42834/2 "2016-02-26T09:40:18Z")

</div>

I don't understand why you'd want to do that, but the easiest way is probably to store today's date in a `@metadata` field and reference that field in the output. Something like this:

```auto
filter {
  ruby {
    code => "event['@metadata']['now'] = Time.new.strftime('%Y-%m-%d')"
  }
}
output {
  elasticsearch {
    ...
    index => "prod-%{@[metadata][now]}"
  }
}

```

---

<div class="post-metadata">

**Author:** ![vikas\_gopal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vikas_gopal/32/47661_2.png) [@vikas\_gopal](https://discuss.elastic.co/u/vikas_gopal)\
**Post date:** [February 26, 2016, 9:48am UTC](https://discuss.elastic.co/t/need-help-to-create-current-date-based-index-in-ls/42834/3 "2016-02-26T09:48:05Z")

</div>

@magnusbaeck,

Thank you for quick response , with above index is getting created but as follows

Index name Doc Count  
prod-%{[metadata][now]} 7089

Actually my requirement is to just create index on current date , something like **prod-2-26-2016**

---

<div class="post-metadata">

**Author:** ![vikas\_gopal](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vikas_gopal/32/47661_2.png) [@vikas\_gopal](https://discuss.elastic.co/u/vikas_gopal)\
**Post date:** [February 26, 2016, 9:49am UTC](https://discuss.elastic.co/t/need-help-to-create-current-date-based-index-in-ls/42834/4 "2016-02-26T09:49:57Z")

</div>

I get it @ was missing , thanks it works

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [February 26, 2016, 9:51am UTC](https://discuss.elastic.co/t/need-help-to-create-current-date-based-index-in-ls/42834/5 "2016-02-26T09:51:52Z")

</div>

Yes, sorry. I updated the post.

---

<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, 5:09am UTC](https://discuss.elastic.co/t/need-help-to-create-current-date-based-index-in-ls/42834/6 "2017-07-06T05:09:37Z")

</div>


