# How to disable nested data type keyword in dynamic mapping

**URL:** <https://discuss.elastic.co/t/how-to-disable-nested-data-type-keyword-in-dynamic-mapping/81157>\
**Category:** Elasticsearch\
**Created:** [April 4, 2017, 1:54pm UTC](https://discuss.elastic.co/t/how-to-disable-nested-data-type-keyword-in-dynamic-mapping/81157 "2017-04-04T13:54:38Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![anand.d](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@anand.d](https://discuss.elastic.co/u/anand.d)\
**Post date:** [April 4, 2017, 1:54pm UTC](https://discuss.elastic.co/t/how-to-disable-nested-data-type-keyword-in-dynamic-mapping/81157/1 "2017-04-04T13:54:38Z")

</div>

I am using Elasticsearch 5.2.2. I have a requirement that in my index, some fields will be defined and some field will be dynamic. But the dynamic mapping is creating a structure something like this:

```auto
"COLOR": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
}

```

I don't want nested keyword field in dynamic mapping. Is there a way to supress it?

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 4, 2017, 2:10pm UTC](https://discuss.elastic.co/t/how-to-disable-nested-data-type-keyword-in-dynamic-mapping/81157/2 "2017-04-04T14:10:02Z")

</div>

Define a template and force the behavior you want for `text` fields.

---

<div class="post-metadata">

**Author:** ![anand.d](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@anand.d](https://discuss.elastic.co/u/anand.d)\
**Post date:** [April 5, 2017, 4:31am UTC](https://discuss.elastic.co/t/how-to-disable-nested-data-type-keyword-in-dynamic-mapping/81157/3 "2017-04-05T04:31:12Z")

</div>

hi David,

Thank you for your reply. I tried using dynamic templates as shown below, but it doesn't seem to work:

```auto
PUT myindex
{
    "settings" : 
    {
        "analysis": 
        {
          "analyzer": 
          {
            "lowercasespaceanalyzer": 
            {
              "type": "custom",
              "tokenizer": "whitespace",
              "filter": ["lowercase"]
            }
          }
        }
    },
    "mappings" : {
        "mytype" : {
            "properties" : {
                "extraction_date" : { "type" : "date",
                "format": "MM-dd-yyyy HH:mm:ss"},
		            "markdown_price" : { "type" : "double" },
		            "regular_price" : { "type" : "double" },
		            "final_price" : { "type" : "double" }
            },
            "dynamic_templates": [
            {
              "strings_as_keywords": {
                "match_mapping_type": "text",
                "mapping": {
                  "type" : "text", "analyzer" : "lowercasespaceanalyzer", "tokenizer": "whitespace", "search_analyzer":"whitespace", "filter": ["lowercase"]
                }
              }
            }
          ]
        }
    }
}

```

After this when i do get mapping, i am still getting dynamic fields with keyword as a nested element.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 5, 2017, 4:45am UTC](https://discuss.elastic.co/t/how-to-disable-nested-data-type-keyword-in-dynamic-mapping/81157/4 "2017-04-05T04:45:04Z")

</div>

Can you give the result of GET \_mapping?  
Can you give the result of GET \_template?

---

<div class="post-metadata">

**Author:** ![anand.d](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@anand.d](https://discuss.elastic.co/u/anand.d)\
**Post date:** [April 5, 2017, 4:59am UTC](https://discuss.elastic.co/t/how-to-disable-nested-data-type-keyword-in-dynamic-mapping/81157/5 "2017-04-05T04:59:26Z")

</div>

hi David,

thanks for the quick reply. I am getting below as a result of get mapping:

```auto
{
  "myindex": {
    "mappings": {
      "mytype": {
        "dynamic_templates": [],
        "properties": {
          "24 hour timer": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "BRAND": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },
          "COLOR": {
            "type": "text",
            "fields": {
              "keyword": {
                "type": "keyword",
                "ignore_above": 256
              }
            }
          },

```

.....

---

<div class="post-metadata">

**Author:** ![anand.d](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@anand.d](https://discuss.elastic.co/u/anand.d)\
**Post date:** [April 5, 2017, 5:00am UTC](https://discuss.elastic.co/t/how-to-disable-nested-data-type-keyword-in-dynamic-mapping/81157/6 "2017-04-05T05:00:31Z")

</div>

i don't want a nested keyword field as it will create extra field in index which will not be good for performance.

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 5, 2017, 5:25am UTC](https://discuss.elastic.co/t/how-to-disable-nested-data-type-keyword-in-dynamic-mapping/81157/7 "2017-04-05T05:25:46Z")

</div>

You can see that GET \_mapping does not give the same result as your PUT myindex.

Did you really run the PUT request ? What is the result ?

---

<div class="post-metadata">

**Author:** ![anand.d](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@anand.d](https://discuss.elastic.co/u/anand.d)\
**Post date:** [April 5, 2017, 5:32am UTC](https://discuss.elastic.co/t/how-to-disable-nested-data-type-keyword-in-dynamic-mapping/81157/8 "2017-04-05T05:32:05Z")

</div>

David i ran the put mapping which only generates mapping for the 4 fields. Rest all are dynamic fields which i am sending via java api. It has close to 1200 columns. After putting the data, i am seeing dynamic mapping fields like 'BRAND', 'COLOR' etc. which are stored as 'text' type but also have 'keyword' type as a nested structure. I dont want that, i only need 'text' type using dynamic template.

---

<div class="post-metadata">

**Author:** ![anand.d](https://avatars.discourse-cdn.com/v4/letter/a/f07891/32.png) [@anand.d](https://discuss.elastic.co/u/anand.d)\
**Post date:** [April 5, 2017, 6:42am UTC](https://discuss.elastic.co/t/how-to-disable-nested-data-type-keyword-in-dynamic-mapping/81157/9 "2017-04-05T06:42:23Z")

</div>

it seems to be working using below code. I removed analyser and tokeniser from dynamic template:

```auto
PUT myindex
{
    "settings" : 
    {
        "index.mapping.total_fields.limit": 2000
    },
    "mappings" : {
        "mytype" : {
            "properties" : {
                "extraction_date" : { "type" : "date",
                "format": "MM-dd-yyyy HH:mm:ss"},
		            "markdown_price" : { "type" : "double" },
		            "regular_price" : { "type" : "double" },
		            "final_price" : { "type" : "double" }
            },
            "dynamic_templates": [
            {
              "strings_as_text": {
                "match_mapping_type": "string",
                "mapping": {
                  "type": "text"
                }
              }
            }
            ]
        }
    }
}

```

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [April 5, 2017, 9:48am UTC](https://discuss.elastic.co/t/how-to-disable-nested-data-type-keyword-in-dynamic-mapping/81157/10 "2017-04-05T09:48:22Z")

</div>

Ok great.

Please format your code using `</>` icon as explained in [this guide](https://discuss.elastic.co/t/about-the-elasticsearch-category/21). It will make your post more readable.

Or use markdown style like:

````
```
CODE
```
````

---

<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 3, 2017, 9:48am UTC](https://discuss.elastic.co/t/how-to-disable-nested-data-type-keyword-in-dynamic-mapping/81157/11 "2017-05-03T09:48:45Z")

</div>

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