# Dynamic\_templates and match\_mapping\_type

**URL:** <https://discuss.elastic.co/t/dynamic-templates-and-match-mapping-type/5845>\
**Category:** Elasticsearch\
**Created:** [November 11, 2011, 5:02pm UTC](https://discuss.elastic.co/t/dynamic-templates-and-match-mapping-type/5845 "2011-11-11T17:02:28Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dawi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dawi/32/2439_2.png) [@dawi](https://discuss.elastic.co/u/dawi)\
**Post date:** [November 11, 2011, 5:02pm UTC](https://discuss.elastic.co/t/dynamic-templates-and-match-mapping-type/5845/1 "2011-11-11T17:02:28Z")

</div>

Hi,

I have introduced a default-mapping.json to store all fields of type  
string in a normal and a reversed version. That works great so far!

My problem is that now I cannot search for date fields anymore. It  
seems that the dynamic  
template applies to date fields as well, although I've  
set "match\_mapping\_type" to "string".  
Elasticsearch says: Field [...] is not a numeric type.

A possible solution would be to use field prefixes and configure  
the dynamic template to only apply to fields that match "string\_\*".  
e.g. document.string\_name, document.string\_email, document.date\_lastlogin,  
...

But I am not sure if this is the best solution.

{

> ```
> "defaultmapping" : {
> "dynamic_templates" : [
> {
> "string_template" : {
> "match" : "*",
> "match_mapping_type" : "string",
> "mapping" : {
> "type" : "multi_field",
> "fields" : {
> "{name}" : {"type": "{dynamic_type}", "index" 
> 
> ```
> 
> : "analyzed", "store" : "yes"},  
> "reverse" : {"type": "{dynamic\_type}", "index"  
> : "analyzed", "index\_analyzer": "reverseanalyzer", "store" : "yes"}  
> }  
> }  
> }  
> }  
> ]  
> }  
> }

Any hints greatly appreciated.

Regards, Daniel

---

<div class="post-metadata">

**Author:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [November 13, 2011, 8:20am UTC](https://discuss.elastic.co/t/dynamic-templates-and-match-mapping-type/5845/2 "2011-11-13T08:20:31Z")

</div>

Heya,

This has been fixed in 0.18 branch and upcoming 0.18.3 (which will be out  
this week).

-shay.banon

On Fri, Nov 11, 2011 at 7:02 PM, dawi [d.wilmer.1980@googlemail.com](mailto:d.wilmer.1980@googlemail.com) wrote:

> Hi,
> 
> I have introduced a default-mapping.json to store all fields of type  
> string in a normal and a reversed version. That works great so far!
> 
> My problem is that now I cannot search for date fields anymore. It  
> seems that the dynamic  
> template applies to date fields as well, although I've  
> set "match\_mapping\_type" to "string".  
> Elasticsearch says: Field [...] is not a numeric type.
> 
> A possible solution would be to use field prefixes and configure  
> the dynamic template to only apply to fields that match "string\_\*".  
> e.g. document.string\_name, document.string\_email, document.date\_lastlogin,  
> ...
> 
> But I am not sure if this is the best solution.
> 
> {
> 
> > ```
> > "defaultmapping" : {
> > "dynamic_templates" : [
> > {
> > "string_template" : {
> > "match" : "*",
> > "match_mapping_type" : "string",
> > "mapping" : {
> > "type" : "multi_field",
> > "fields" : {
> > "{name}" : {"type": "{dynamic_type}", "index"
> > 
> > ```
> > 
> > : "analyzed", "store" : "yes"},  
> > "reverse" : {"type": "{dynamic\_type}",  
> > "index" : "analyzed", "index\_analyzer": "reverseanalyzer", "store" : "yes"}  
> > }  
> > }  
> > }  
> > }  
> > ]  
> > }  
> > }
> 
> Any hints greatly appreciated.
> 
> Regards, Daniel

---

<div class="post-metadata">

**Author:** ![dawi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dawi/32/2439_2.png) [@dawi](https://discuss.elastic.co/u/dawi)\
**Post date:** [November 14, 2011, 7:47am UTC](https://discuss.elastic.co/t/dynamic-templates-and-match-mapping-type/5845/3 "2011-11-14T07:47:16Z")

</div>

Ok, thanks for this info. 🙂

---

<div class="post-metadata">

**Author:** ![dawi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dawi/32/2439_2.png) [@dawi](https://discuss.elastic.co/u/dawi)\
**Post date:** [November 14, 2011, 3:41pm UTC](https://discuss.elastic.co/t/dynamic-templates-and-match-mapping-type/5845/4 "2011-11-14T15:41:50Z")

</div>

Hi Shay,

I just tested with the latest repository version 0.19.0 SNAPSHOT which  
includes commit:

\*Mapping: Improve applying guessed types on dynamic templates, closes #1446.  
\*  
But the problem still exists.

If I don't use this dynamic\_template I am able to search for strings and  
dates.  
If I use the given dynamic mapping above, then i can only search for  
strings but for dates it says: Field [...] is not a numeric type.

If you need more information about this or maybe some logs, please let me  
know.

Regards,  
Daniel

---

<div class="post-metadata">

**Author:** ![dawi](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dawi/32/2439_2.png) [@dawi](https://discuss.elastic.co/u/dawi)\
**Post date:** [November 14, 2011, 4:08pm UTC](https://discuss.elastic.co/t/dynamic-templates-and-match-mapping-type/5845/5 "2011-11-14T16:08:05Z")

</div>

Hi Shay,

my mistake.

I've tested with the actual 0.19.0 SNAPSHOT and everything works as  
expected!

Regards,  
Daniel

---

<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 6, 2017, 3:48am UTC](https://discuss.elastic.co/t/dynamic-templates-and-match-mapping-type/5845/6 "2017-07-06T03:48:44Z")

</div>


