# Problem with Mapping Templates

**URL:** <https://discuss.elastic.co/t/problem-with-mapping-templates/247370>\
**Category:** Elasticsearch\
**Created:** [September 3, 2020, 11:08am UTC](https://discuss.elastic.co/t/problem-with-mapping-templates/247370 "2020-09-03T11:08:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ashu1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ashu1/32/75042_2.png) [@ashu1](https://discuss.elastic.co/u/ashu1)\
**Post date:** [September 3, 2020, 11:08am UTC](https://discuss.elastic.co/t/problem-with-mapping-templates/247370/1 "2020-09-03T11:08:43Z")

</div>

I created a field mapping for keyword only field and ingested the data to ES,but I could still see field.keyword in my index.  
In my case field name is AB.Field1  
Is it due to .(dot) in my field Name or any other issue?

```auto
   PUT _template/test1
{
    "order": 9,
    "version": 1,
    "index_patterns": [
      "test1*",
      "test2*"
    ],
    "settings": {
      "index": {
        "number_of_shards": "2",
        "number_of_replicas": "1",
        "refresh_interval": "5s"
      }
    },
    "mappings": {
        "dynamic_templates": [
          {
            "keyword_only_field": {
              "match_pattern": "regex",
              "match": "^(AB.Field1|BC.Field1|AB.Field2|BC.Field2)$",
              "match_mapping_type": "string",
              "mapping": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }
        ]
    },
    "aliases": {}
}

```

---

<div class="post-metadata">

**Author:** ![Emanuil](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/emanuil/32/36783_2.png) [@Emanuil](https://discuss.elastic.co/u/Emanuil)\
**Post date:** [September 4, 2020, 12:23am UTC](https://discuss.elastic.co/t/problem-with-mapping-templates/247370/2 "2020-09-04T00:23:08Z")

</div>

> [@ashu1](#):
>
> Is it due to .(dot) in my field Name or any other issue?

Yes, it is due to the dot. You need to expand the field definition in the mapping.

You could define a regular (not dynamic) mapping for `{"AB": {"Field1": <keyword only definition>}}`. Your regex is currently just a convenient list of field names, but it's not doing any wider matching like using wildcards `*`.

If you're sure `Field1` will always need to be keyword-only across all `AB`, `BC` etc. parent objects, you could use a simple `"match": "Field1"`dynamic template without regex. E.g.:

```auto
PUT _template/test1
{
    "order": 9,
    "version": 1,
    "index_patterns": [
      "test1*",
      "test2*"
    ],
    "settings": {
      "index": {
        "number_of_shards": "2",
        "number_of_replicas": "1",
        "refresh_interval": "5s"
      }
    },
    "mappings": {
        "dynamic_templates": [
          {
            "keyword_only_field": {
              "match": "Field1",
              "match_mapping_type": "string",
              "mapping": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          }
        ]
    },
    "aliases": {}
}

```

I tested that in Kibana Dev Console on Elasticsearch 7.9.1. After saving that dynamic template:

```auto
PUT test1index

PUT test1index/_doc/testdoc1
{
  "AB": {"Field1": "value1"},
  "regular_field": "regular value"
}

GET test1index/_doc/testdoc1

GET test1index/_mapping

```

The last query results in

```auto
"properties" : {
        "AB" : {
          "properties" : {
            "Field1" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        },
        "regular_field" : {
          "type" : "text",
          "fields" : {
            "keyword" : {
              "type" : "keyword",
              "ignore_above" : 256
            }
          }
        }
      }

```

which seems to be what you want.

---

<div class="post-metadata">

**Author:** ![ashu1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ashu1/32/75042_2.png) [@ashu1](https://discuss.elastic.co/u/ashu1)\
**Post date:** [September 5, 2020, 4:08pm UTC](https://discuss.elastic.co/t/problem-with-mapping-templates/247370/3 "2020-09-05T16:08:37Z")

</div>

Great Thanks a lot!

---

<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:** [October 3, 2020, 4:08pm UTC](https://discuss.elastic.co/t/problem-with-mapping-templates/247370/4 "2020-10-03T16:08:55Z")

</div>

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