# Always add a not\_analyzed field to strings template mapping

**URL:** <https://discuss.elastic.co/t/always-add-a-not-analyzed-field-to-strings-template-mapping/27561>\
**Category:** Elasticsearch\
**Created:** [August 18, 2015, 8:05am UTC](https://discuss.elastic.co/t/always-add-a-not-analyzed-field-to-strings-template-mapping/27561 "2015-08-18T08:05:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![GX1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gx1/32/62846_2.png) [@GX1](https://discuss.elastic.co/u/GX1)\
**Post date:** [August 18, 2015, 8:05am UTC](https://discuss.elastic.co/t/always-add-a-not-analyzed-field-to-strings-template-mapping/27561/1 "2015-08-18T08:05:13Z")

</div>

Hi all, I have run into a problem where I have a value 'testing-beta' when I try filter this field I get no results, from my understanding its the analyser that splits it into tokens, I have tried creating a dynamic template mapping for all string values (similar to logstash) but it does not seem to have any effect.

What I want to achieve is all string fields (at all levels) to have a "{name}.raw" field that is not\_analyzed or a way to filter the \_source value directly. I deleted the index then added the template then reindexed all the data.

template:

```
{
    "template" : "MyIndex",
    "mappings" : {
        "_default_" : {
            "dynamic_templates" : [ {
                "string_fields" : {
                        "path_match" : "*",
                        "match_mapping_type" : "string",
                        "mapping" : {
                            "type": "multi_field",
                            "fields": {
                                "{name}": {
                                    "type": "{dynamic_type}",
                                    "index": "analyzed"
                                },
                                "raw": {
                                    "type": "{dynamic_type}",
                                    "index": "not_analyzed"
                                }
                            }
                        }
                    }
                }
            ]
        }
    }
}
```

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [August 18, 2015, 11:33pm UTC](https://discuss.elastic.co/t/always-add-a-not-analyzed-field-to-strings-template-mapping/27561/2 "2015-08-18T23:33:15Z")

</div>

> [@GX1](#):
>
> "type": "{dynamic\_type}",

Is that what you actually have in the mapping, and is that the actual type?

---

<div class="post-metadata">

**Author:** ![GX1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gx1/32/62846_2.png) [@GX1](https://discuss.elastic.co/u/GX1)\
**Post date:** [August 19, 2015, 4:03am UTC](https://discuss.elastic.co/t/always-add-a-not-analyzed-field-to-strings-template-mapping/27561/3 "2015-08-19T04:03:26Z")

</div>

I understood that the template would create a mapping and that that would match all types, I changed it to

```
"type": "string",

```

but still get an error "bad request"

---

<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 5, 2017, 11:55pm UTC](https://discuss.elastic.co/t/always-add-a-not-analyzed-field-to-strings-template-mapping/27561/4 "2017-07-05T23:55:07Z")

</div>


