# Custom mapping in apm index

**URL:** https://discuss.elastic.co/t/custom-mapping-in-apm-index/261988
**Category:** APM
**Tags:** rum
**Created:** [January 23, 2021, 12:43pm UTC](https://discuss.elastic.co/t/custom-mapping-in-apm-index/261988 "2021-01-23T12:43:35Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Smrithin\_N\_S](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/smrithin_n_s/32/78403_2.png) [@Smrithin\_N\_S](https://discuss.elastic.co/u/Smrithin_N_S)
#### Post date: [January 23, 2021, 12:43pm UTC](https://discuss.elastic.co/t/custom-mapping-in-apm-index/261988/1 "2021-01-23T12:43:36Z")

</div>

I have a deployment in cloud elastic using for apm:

apm metrics are being pushed from Nodejs(fastify framwork). I need to add a custom property mapping to the transaction index.

I am able to add the mapping using

```auto
PUT apm*/_mapping
{
  "properties": {
      "transaction.custom.body.deviceId": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256,
            "index": true
          }
        },
        "index": true
      }
} 
}

```

Deployment version: v7.10.1

However during rollover the new index wont have this mapping. I understand that I need to update the mapping in the index template.

```auto

       {
         "apm-7.10.0-transaction" : {
           "order" : 2,
           "index_patterns" : [
             "apm-7.10.0-transaction*"
           ],
           "settings" : {
             "index" : {
               "lifecycle" : {
                 "name" : "apm-rollover-30-days",
                 "rollover_alias" : "apm-7.10.0-transaction"
               }
             }
           },
           "mappings" : { },
           "aliases" : { }
         }
       }

```

The mapping here is seen as empty. Could you help me with adding the mapping to template? Its cloud-elastic, so I am confused if it needs to be added in (user-setting-override)apm-server.yml or directly to template.

Thanks in advance.

---

<div class="post-metadata">

### Author: ![stephenb](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/stephenb/32/40856_2.png) [@stephenb](https://discuss.elastic.co/u/stephenb)
#### Post date: [January 23, 2021, 8:04pm UTC](https://discuss.elastic.co/t/custom-mapping-in-apm-index/261988/2 "2021-01-23T20:04:46Z")

</div>

Hi @Smrithin_N_S

Well there are perhaps an is easier ways to do this...

But to first answer your questions the mappings are defined in the index template

`GET _template/apm-7.10.0`

This defines the mapping for any index that matches the pattern

```
"index_patterns" : [
  "apm-7.10.0*"
],

```

In that there are dynamic template and so that you can add fields and a mapping will automatically be generated.

Option 1) So for example if you added the field you are interested under `fields.*` or `labels.*` or `even container.labels.*` a mapping would automatically be created these would be of type `keyword`

```
  "dynamic_templates" : [
    {
      "labels" : {
        "path_match" : "labels.*",
        "mapping" : {
          "type" : "keyword"
        },
        "match_mapping_type" : "string"
      }
    },
    {
      "container.labels" : {
        "path_match" : "container.labels.*",
        "mapping" : {
          "type" : "keyword"
        },
        "match_mapping_type" : "string"
      }
    },
    {
      "fields" : {
        "path_match" : "fields.*",
        "mapping" : {
          "type" : "keyword"
        },
        "match_mapping_type" : "string"
      }
    },
    {
      "docker.container.labels" : {
        "path_match" : "docker.container.labels.*",
        "mapping" : {
          "type" : "keyword"
        },
        "match_mapping_type" : "string"
      }
    },

```

If you could put your fields under any of these your ready to go... Note you may still need to update the index-pattern

Option 2) really if you just add this field to a document and it is _not_ an integer it will be automatically added with the mapping below and all you would do is refresh the index patter an it would be there... always... then the same would happen when a new index is create... this just leverages Elasticsearch automatic mapping creation

```
    "my-new-field" : {
      "type" : "text",
      "fields" : {
        "keyword" : {
          "type" : "keyword",
          "ignore_above" : 256
        }
      }
    }

```

Option 3) Now if you are really set on adding your exact field as above you would add it to this index template ... of course when you update to 7.10.1 you will need to add it etc. that is why I would probably use one of the predefined fields.

We have now introduced composable index template which will probably ease this in the future but it looks like the APM index templates have not migrated to that yet.

Hopefully this help a bit

---

<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: [February 13, 2021, 4:05pm UTC](https://discuss.elastic.co/t/custom-mapping-in-apm-index/261988/3 "2021-02-13T16:05:20Z")

</div>

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