# Need help with a dynamic mapping

**URL:** <https://discuss.elastic.co/t/need-help-with-a-dynamic-mapping/211639>\
**Category:** Elasticsearch\
**Created:** [December 12, 2019, 11:44am UTC](https://discuss.elastic.co/t/need-help-with-a-dynamic-mapping/211639 "2019-12-12T11:44:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![matd](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matd/32/9892_2.png) [@matd](https://discuss.elastic.co/u/matd)\
**Post date:** [December 12, 2019, 11:44am UTC](https://discuss.elastic.co/t/need-help-with-a-dynamic-mapping/211639/1 "2019-12-12T11:44:44Z")

</div>

I'm struggling with dynamic mappings. My docs (coming from logs) include a `parameters` object with lots of nested properties, that I want to partially index.

Especially, I have some fields that I want to dynamically map to token type, ex:  
`parameters.applicationId`  
`parameters.userId`  
... etc (all what I need is first level in `parameters`)

And some fields to exclude:  
`parameters.authorization`  
`parameters.access_token`  
`parameters.body.*` (body and all subproperties)

I tried with regex, or playing on orders of dynamic\_mappings without success. Either it indexes nothing, or indexes a field I don't want.

Right now, I tried this (and it indexes `access_token` wrongly).

```auto
PUT _template/calls
{
  "index_patterns": ["calls-v1.1.0*"],
  "mappings" : {
    "_source" : {
      "enabled" : true
    },
    "dynamic_templates": [
      {
        "parameters_template": {
          "path_match": "parameters.access_token",
          "mapping": { "enabled": false }
        }
      },
      {
        "parameters_template": {
          "path_match": "parameters.authorization",
          "mapping": { "enabled": false }
        }
      },
      {
        "parameters_template": {
          "path_match": "parameters.body",
          "mapping": { "enabled": false }
        }
      },
      {
        "parameters_template": {
          "path_match": "parameters.*",
          "mapping": {
            "type": "keyword"
          }
        }
      }
    ],
    "properties" : {
      "headers" : {
        "enabled" : false
      },
      "stack" : {
        "type" : "keyword"
      },
      ...

```

```auto
GET /calls-v1.1.0-2019-12-reindexed/_mapping
    {
      "calls-v1.1.0-2019-12-reindexed" : {
        "mappings" : {
          "dynamic_templates" : [...],
          "properties" : {
            ...
            "parameters" : {
              "properties" : {
                "accessId" : {
                  "type" : "keyword"
                },
                "access_token" : {
                  "type" : "text"
                },
           ...

```

---

<div class="post-metadata">

**Author:** ![matd](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matd/32/9892_2.png) [@matd](https://discuss.elastic.co/u/matd)\
**Post date:** [December 13, 2019, 1:10pm UTC](https://discuss.elastic.co/t/need-help-with-a-dynamic-mapping/211639/2 "2019-12-13T13:10:13Z")

</div>

dynamic template actually...

---

<div class="post-metadata">

**Author:** ![matd](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matd/32/9892_2.png) [@matd](https://discuss.elastic.co/u/matd)\
**Post date:** [December 13, 2019, 5:56pm UTC](https://discuss.elastic.co/t/need-help-with-a-dynamic-mapping/211639/3 "2019-12-13T17:56:13Z")

</div>

Managed to do it by mapping explicitly properties I wanted to turn off with {enabled:false}, and using the template part only for enabled ones.

---

<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:** [January 10, 2020, 6:02pm UTC](https://discuss.elastic.co/t/need-help-with-a-dynamic-mapping/211639/4 "2020-01-10T18:02:46Z")

</div>

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