# Help with dynamic mapping

**URL:** <https://discuss.elastic.co/t/help-with-dynamic-mapping/57538>\
**Category:** Elasticsearch\
**Created:** [August 9, 2016, 12:47am UTC](https://discuss.elastic.co/t/help-with-dynamic-mapping/57538 "2016-08-09T00:47:50Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![stecino](https://avatars.discourse-cdn.com/v4/letter/s/ea666f/32.png) [@stecino](https://discuss.elastic.co/u/stecino)\
**Post date:** [August 9, 2016, 12:47am UTC](https://discuss.elastic.co/t/help-with-dynamic-mapping/57538/1 "2016-08-09T00:47:50Z")

</div>

Hello i have following being written to ES

```auto
{
              "@timestamp" => "2016-08-09T00:39:10.741Z",
              "input_type" => "log",
                  "offset" => 20870063,
                  "source" => "/usr/local/nginx/access.log",
                    "tags" => [
        [0] "ypu"
    ],
                    "type" => "nginx",
                "@version" => "1",
                   "kafka" => {
              "msg_size" => 1588,
                 "topic" => "logs-ev1",
        "consumer_group" => "logstash",
             "partition" => 11,
                   "key" => nil
    },
              "nginx_host" => "blah.com",
             "remote_addr" => "10.x.x.19",
    "http_x_forwarded_for" => "xx.xx.xx.10",
               "timestamp" => "09/Aug/2016:00:39:10 +0000",
                    "verb" => "POST",
                 "request" => "/blah/test",
             "httpversion" => "1.1",
                "response" => 200,
                   "bytes" => "2",
                "referrer" => "\"http://www.test.com/detroit-mi/mip/test-llc-482631255?sem=tas%3Dbingspot%26acct%3Dautosem%26adgroup%3Dautosem_spotbuy\"",
                   "agent" => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2486.0 Safari/537.36 Edge/13.10586",
                  "cookie" => "blah",
           "response_time" => 0.064,
                "platform" => "test"
}

```

I want to setup dynamic template where it will set following fields to not\_analyzed

nginx\_host  
agent  
referrer  
cookie  
http\_x\_forwarded\_for  
httpversion  
request  
remote\_addr

depending on a record, I may have fields like http\_x\_forwarded1 and http\_x\_forwarded2, i need to be able to set those to not\_analyzed as well  
and I would like to set response and response\_time to number

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [August 9, 2016, 8:29am UTC](https://discuss.elastic.co/t/help-with-dynamic-mapping/57538/2 "2016-08-09T08:29:11Z")

</div>

You don't need dynamic templates for this, you could use simple mappings? Eg.

```auto
{
  "your_type_name": {
    "properties": {
      "nginx_host": {
        "type": "string",
        "index": "not_analyzed"
      },
      ...same for other not_analyzed fields...,
      "response_time": {
        "type": "integer"
      }
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![stecino](https://avatars.discourse-cdn.com/v4/letter/s/ea666f/32.png) [@stecino](https://discuss.elastic.co/u/stecino)\
**Post date:** [August 9, 2016, 5:32pm UTC](https://discuss.elastic.co/t/help-with-dynamic-mapping/57538/3 "2016-08-09T17:32:38Z")

</div>

The data coming in may change, so fields may go in and out with the newly index. I have a rolling index. This set of fields will be static.

---

<div class="post-metadata">

**Author:** ![jpountz](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jpountz/32/45836_2.png) [@jpountz](https://discuss.elastic.co/u/jpountz)\
**Post date:** [August 9, 2016, 8:57pm UTC](https://discuss.elastic.co/t/help-with-dynamic-mapping/57538/4 "2016-08-09T20:57:16Z")

</div>

If you have rolling indices, then this would be best put in an index template, so that mappings will be automatically added when indices are created.

---

<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 5, 2017, 10:29pm UTC](https://discuss.elastic.co/t/help-with-dynamic-mapping/57538/5 "2017-07-05T22:29:02Z")

</div>


