# Disabling dynamic mapping of an object's fields, while using dynamic templates to copy\_to custom fields

**URL:** <https://discuss.elastic.co/t/disabling-dynamic-mapping-of-an-objects-fields-while-using-dynamic-templates-to-copy-to-custom-fields/83090>\
**Category:** Elasticsearch\
**Created:** [April 20, 2017, 4:35pm UTC](https://discuss.elastic.co/t/disabling-dynamic-mapping-of-an-objects-fields-while-using-dynamic-templates-to-copy-to-custom-fields/83090 "2017-04-20T16:35:12Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rlvoyer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rlvoyer/32/4928_2.png) [@rlvoyer](https://discuss.elastic.co/u/rlvoyer)\
**Post date:** [April 20, 2017, 4:35pm UTC](https://discuss.elastic.co/t/disabling-dynamic-mapping-of-an-objects-fields-while-using-dynamic-templates-to-copy-to-custom-fields/83090/1 "2017-04-20T16:35:12Z")

</div>

I am indexing data (using Elasticsearch 5.2.x) where I don't know in advance the set of all fields in my records. Since the number of fields is unbounded, I want to disable dynamic mapping of those fields. However, I would like to use dynamic templates to selectively index certain fields (via `copy_to`). It seems as though if I use `"enabled": false` to ensure that my object isn't dynamically mapped, then the dynamic template doesn't actually work (ie. none of the object's fields get copied into the `copy_to` field.)

Here is my current mapping:

```auto
{
  "dynamic": "strict",
  "dynamic_templates": [
    {
      "row_fts": {
        "match_mapping_type": "string",
        "path_match": "data.*",
        "mapping": { "type": "text", "copy_to": "row_fts" }
      }
    }
  ],
  "properties": {
    "row_id": { "type": "long" },
    "row_type": { "type": "keyword" },
    "row_fts": { "type": "text", "analyzer": "standard" },
    "data": {
      "type": "object",
      "dynamic": true,
      "enabled": false
    }
  }
}

```

Is there a way to achieve this? Thanks for your help!

---

<div class="post-metadata">

**Author:** ![rlvoyer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rlvoyer/32/4928_2.png) [@rlvoyer](https://discuss.elastic.co/u/rlvoyer)\
**Post date:** [April 21, 2017, 6:09pm UTC](https://discuss.elastic.co/t/disabling-dynamic-mapping-of-an-objects-fields-while-using-dynamic-templates-to-copy-to-custom-fields/83090/2 "2017-04-21T18:09:11Z")

</div>

Well, through some trial and error, I've discovered that the following gets me part of the way there:

```auto
{
  "dynamic": "strict",
  "dynamic_templates": [
    {
      "row_fts": {
        "match_mapping_type": "string",
        "path_match": "data.*",
        "mapping": { "type": "text", "copy_to": "row_fts", "index": "no" }
      }
    }
  ],
  "properties": {
    "row_id": { "type": "long" },
    "row_type": { "type": "keyword" },
    "row_fts": { "type": "text", "analyzer": "standard" },
    "data": {
      "dynamic": true,
      "type": "object"
    }
  }
}

```

While this does update the mapping with each of the string subfields of the `data` field, it doesn't actually index those subfields.

---

<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 19, 2017, 6:18pm UTC](https://discuss.elastic.co/t/disabling-dynamic-mapping-of-an-objects-fields-while-using-dynamic-templates-to-copy-to-custom-fields/83090/3 "2017-05-19T18:18:19Z")

</div>

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