# Issue with ignore\_malformed + string keyword type

**URL:** https://discuss.elastic.co/t/issue-with-ignore-malformed-string-keyword-type/235736
**Category:** Elasticsearch
**Created:** [June 4, 2020, 10:53am UTC](https://discuss.elastic.co/t/issue-with-ignore-malformed-string-keyword-type/235736 "2020-06-04T10:53:18Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Xavier\_Romero](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/xavier_romero/32/63274_2.png) [@Xavier\_Romero](https://discuss.elastic.co/u/Xavier_Romero)
#### Post date: [June 4, 2020, 10:53am UTC](https://discuss.elastic.co/t/issue-with-ignore-malformed-string-keyword-type/235736/1 "2020-06-04T10:53:18Z")

</div>

Hello,

I have some data with an object named "data". I need to perform aggregations by fields inside the "data" object, so I need the keyword type for all strings. At the same time, I need to set the ignore\_malformed to true for other types.

I realized that this mapping automatically disables the keyword extra field for all strings inside "data"... ¿?

```
DELETE /_template/test
PUT /_template/test
{
 	"index_patterns": ["test"],
	"mappings": {
 	"properties": {
 			    "data": {
            "type": "object"
           }
 		},
 		"dynamic_templates": [
      {
        "data": {
          "path_match": "data.*",
          "mapping": { "ignore_malformed": true }
        }
      }
 		]
 	}
 }

DELETE /test
PUT /test/_doc/1
{
  "data.field": "hellow world"
}
GET /test/_mapping/

```

Output:

```
{
  "test" : {
    "mappings" : {
      "dynamic_templates" : [
        {
          "data" : {
            "path_match" : "data.*",
            "mapping" : {
              "ignore_malformed" : true
            }
          }
        }
      ],
      "properties" : {
        "data" : {
          "properties" : {
            "field" : {
              "type" : "text"
            }
          }
        }
      }
    }
  }
}

```

Just removing the dynamic mapping (for ignore\_malformed), I get the expected extra keyword field:

```
{
  "test" : {
    "mappings" : {
      "properties" : {
        "data" : {
          "properties" : {
            "field" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            }
          }
        }
      }
    }
  }
}

```

Setting an extra mapping to set strings to keyword does not work, since it looks like only the first rule that matches is applied:

```
DELETE /_template/test
PUT /_template/test
{
 	"index_patterns": ["test"],
	"mappings": {
 	"properties": {
 			    "data": {
            "type": "object"
           }
 		},
 		"dynamic_templates": [
      {
        "data": {
          "path_match": "data.*",
          "mapping": { "ignore_malformed": true }
        }
      },
      {
        "data_keyword": {
          "path_match": "data.*",
          "match_mapping_type": "string",
          "mapping": { "type": "keyword" }
        }
      }
 		]
 	}
 }

DELETE /test
PUT /test/_doc/1
{
  "data.field": "hellow world"
}
GET /test/_mapping

```

Output:

```
{
  "test" : {
    "mappings" : {
      "dynamic_templates" : [
        {
          "data" : {
            "path_match" : "data.*",
            "mapping" : {
              "ignore_malformed" : true
            }
          }
        },
        {
          "data_keyword" : {
            "path_match" : "data.*",
            "match_mapping_type" : "string",
            "mapping" : {
              "type" : "keyword"
            }
          }
        }
      ],
      "properties" : {
        "data" : {
          "properties" : {
            "field" : {
              "type" : "text"
            }
          }
        }
      }
    }
  }
}

```

So.. how can I get the ignore\_malformed set to true and at the same time keyword type for my string fields?

---

<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: [July 2, 2020, 10:53am UTC](https://discuss.elastic.co/t/issue-with-ignore-malformed-string-keyword-type/235736/2 "2020-07-02T10:53:21Z")

</div>

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