# Field alias in dynamic template

**URL:** <https://discuss.elastic.co/t/field-alias-in-dynamic-template/204159>\
**Category:** Elasticsearch\
**Created:** [October 18, 2019, 3:18am UTC](https://discuss.elastic.co/t/field-alias-in-dynamic-template/204159 "2019-10-18T03:18:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![jasony](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@jasony](https://discuss.elastic.co/u/jasony)\
**Post date:** [October 18, 2019, 3:18am UTC](https://discuss.elastic.co/t/field-alias-in-dynamic-template/204159/1 "2019-10-18T03:18:44Z")

</div>

Hello,

Is it possible to put field alias in dynamic template? if so, can you please share some samples with field alias? I tried to find elastic document but couldn't find.

FYI,  
currently I am working on below template but I need to add field alias (e.g. "time-taken" field alias with "time-taken-ms" field).

please advise. thank you!!

```
PUT _template/cloudfront_logs
{
  "index_patterns": [
    "cloudfront_*"
  ],
  "settings": {
    "number_of_replicas": 1,
    "number_of_shards": 3
  },
  "mappings": {
    "_doc": {
      "dynamic_templates": [
        {
          "time-taken": {
            "mapping": {
              "type": "long"
            },
            "match": "time-taken"
          }
        },
        {
          "content-length": {
            "mapping": {
              "type": "long"
            },
            "match": "content-length"
          }
        },
        {
          "cs-bytes": {
            "mapping": {
              "type": "long"
            },
            "match": "cs-bytes"
          }
        },
        {
          "sc-bytes": {
            "mapping": {
              "type": "long"
            },
            "match": "sc-bytes"
          }
        },
        {
          "strings": {
            "mapping": {
              "type": "keyword"
            },
            "match_mapping_type": "string"
          }
        }
      ]
    }
  }
}
```

---

<div class="post-metadata">

**Author:** ![jasony](https://avatars.discourse-cdn.com/v4/letter/j/a3d4f5/32.png) [@jasony](https://discuss.elastic.co/u/jasony)\
**Post date:** [October 18, 2019, 3:34am UTC](https://discuss.elastic.co/t/field-alias-in-dynamic-template/204159/2 "2019-10-18T03:34:47Z")

</div>

self replying.....

I guess I solved my problem as below (highlighted with bold). 🙂

```
PUT _template/cloudfront_logs
{
  "index_patterns": [
    "cloudfront_*"
  ],
  "settings": {
    "number_of_replicas": 1,
    "number_of_shards": 3
  },
  "mappings": {
    "_doc": {
      **"properties": {**
 **"c-ip": {**
 **"type": "keyword"**
 **},**
 **"client-ip": {**
 **"type": "alias",**
 **"path": "c-ip"**
 **}**
 **},**
      "dynamic_templates": [
        {
          "time-taken": {
            "mapping": {
              "type": "long"
            },
            "match": "time-taken"
          }
        },
...
```

---

<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 15, 2019, 3:35am UTC](https://discuss.elastic.co/t/field-alias-in-dynamic-template/204159/3 "2019-11-15T03:35:00Z")

</div>

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