# Mapping on Index names with Date

**URL:** <https://discuss.elastic.co/t/mapping-on-index-names-with-date/81371>\
**Category:** Elasticsearch\
**Created:** [April 5, 2017, 8:59pm UTC](https://discuss.elastic.co/t/mapping-on-index-names-with-date/81371 "2017-04-05T20:59:33Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![zero1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zero1/32/17087_2.png) [@zero1](https://discuss.elastic.co/u/zero1)\
**Post date:** [April 5, 2017, 8:59pm UTC](https://discuss.elastic.co/t/mapping-on-index-names-with-date/81371/1 "2017-04-05T20:59:33Z")

</div>

I have a document which I index this way:

> POST notifications/file  
> {  
> "system" : "server 1",  
> "date" : "2017-04-04 10:00:00"  
> }

The date was mapped dynamically to string. In order to utilize the date in Kibana, I did this prior to indexing:

> PUT notifications  
> {  
> "mappings": {  
> "file": {  
> "properties": {  
> "date": {  
> "type": "date",  
> "format": "yyyy-MM-dd HH:mm:ss"  
> }  
> }  
> }  
> }  
> }

That would be all fine but then I read in the examples that they are using Index names with date, such as:

> POST notifications-2017.04.04/file  
> {  
> "system" : "server 1",  
> "date" : "2017-04-04 10:00:00"  
> }

The problem now is when I do the following using the same PUT data (as above):

> PUT **notifications \***

If I do it before indexing the first POST data, it complains of an invalid index name format.  
If after, it complains that the 'date' field has a type "string" already.  
I'd like the mapping to reflect on indices that will be generated in the future.

I'm reading the Dynamic Mapping topic from the Documentation, they don't have examples that fit my scenario.  
I'd like to know how to implement mapping with this kind of Index name?

---

<div class="post-metadata">

**Author:** ![dakrone](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dakrone/32/23351_2.png) [@dakrone](https://discuss.elastic.co/u/dakrone)\
**Post date:** [April 5, 2017, 11:01pm UTC](https://discuss.elastic.co/t/mapping-on-index-names-with-date/81371/2 "2017-04-05T23:01:29Z")

</div>

It sounds like what you want is a dynamic template, which will apply some settings/mappings every time a new index is created that matches the template. For example:

```
PUT /_template/notification-template
{
  "template": "notification-*",
  "mappings": {
    "file": {
      "properties": {
        "date": {
          "type": "date",
          "format": "yyyy-MM-dd HH:mm:ss"
        }
      }
    }
  }
}

```

The `notification-*` means that the template will be applied every time a new index starting with "notification-" is created.

---

<div class="post-metadata">

**Author:** ![zero1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/zero1/32/17087_2.png) [@zero1](https://discuss.elastic.co/u/zero1)\
**Post date:** [April 6, 2017, 4:52am UTC](https://discuss.elastic.co/t/mapping-on-index-names-with-date/81371/3 "2017-04-06T04:52:30Z")

</div>

It worked. Thanks!

---

<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:** [May 4, 2017, 4:52am UTC](https://discuss.elastic.co/t/mapping-on-index-names-with-date/81371/4 "2017-05-04T04:52:30Z")

</div>

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