# Template index with dynamic mapping to float

**URL:** <https://discuss.elastic.co/t/template-index-with-dynamic-mapping-to-float/43407>\
**Category:** Elasticsearch\
**Created:** [March 3, 2016, 3:35pm UTC](https://discuss.elastic.co/t/template-index-with-dynamic-mapping-to-float/43407 "2016-03-03T15:35:25Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![LiorK](https://avatars.discourse-cdn.com/v4/letter/l/65b543/32.png) [@LiorK](https://discuss.elastic.co/u/LiorK)\
**Post date:** [March 3, 2016, 3:35pm UTC](https://discuss.elastic.co/t/template-index-with-dynamic-mapping-to-float/43407/1 "2016-03-03T15:35:25Z")

</div>

Hi all, 🙂  
how I can manage and deploy a dynamic mapping to elasticsearch (which i will merge into index template later on) that will take a specific type and all his fields will be converted to float type.

The point is to not mutate the fields in logstash for the specific type.

**my not working example (via sense):**  
type-a fields will be converted into floats and type-b will be converted to string not\_analyzed

PUT /\_template/my\_type  
{  
"template": "test\*",  
"settings": {  
"number\_of\_replicas": "1",  
"number\_of\_shards": "5",  
"refresh\_interval": "5s"  
},  
"mappings": {  
"type-a" : {  
"dynamic\_templates": [  
{  
"float\_fields": {  
"mapping": { "type": "float", "null\_value": "NULL", "omit\_norms": true},  
"match": "_",  
"match\_mapping\_type": "float"  
}  
}  
]  
},  
"type-b" : {  
"dynamic\_templates": [  
{  
"string\_fields": {  
"mapping": { "index": "not\_analyzed", "type": "string", "omit\_norms": true},  
"match" : "_",  
"match\_mapping\_type": "string"  
}  
}  
]  
}  
}  
}

## thanks! 😄

---

<div class="post-metadata">

**Author:** ![LiorK](https://avatars.discourse-cdn.com/v4/letter/l/65b543/32.png) [@LiorK](https://discuss.elastic.co/u/LiorK)\
**Post date:** [March 6, 2016, 10:06am UTC](https://discuss.elastic.co/t/template-index-with-dynamic-mapping-to-float/43407/2 "2016-03-06T10:06:55Z")

</div>

bump 😃

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [March 6, 2016, 9:21pm UTC](https://discuss.elastic.co/t/template-index-with-dynamic-mapping-to-float/43407/3 "2016-03-06T21:21:15Z")

</div>

Can you give example of the data you intend to index and how you expect it to be mapped?

---

<div class="post-metadata">

**Author:** ![LiorK](https://avatars.discourse-cdn.com/v4/letter/l/65b543/32.png) [@LiorK](https://discuss.elastic.co/u/LiorK)\
**Post date:** [March 7, 2016, 5:46am UTC](https://discuss.elastic.co/t/template-index-with-dynamic-mapping-to-float/43407/4 "2016-03-07T05:46:36Z")

</div>

**_Edit:_**  
Its generally kind of dynamic mapping for float/double, if you have any example that I can use it will be much appreciate. Fields mapping into float instead of string with dynamic mapping so all new fields as well will be floats

I have csv with only float/double values inside it, I don't want for each field to write mutate on logstash conf and to manage the conf it self (if csv columns changes), therefore I created a template index with in it I added dynamic mapping for float (tried it with double as well) but eventually the mapping remain string

**for example:**  
file with the columns col\_a, col\_b, col\_c  
1.3,1.4,1.5  
1.6,1.7,1.8

col\_a, col\_b, col\_c need to be float/double without me saying mutate and any other field that will be added to this type (this file) will be mapped as float/double before inserting to elasticsearch.  
_Any ideas?_

**my template index with dynamic mapping:**  
PUT /\_template/test  
{  
"template": "test\*",  
"mappings": {  
"testme" : {  
"dynamic\_templates": [  
{  
"float\_fields": {  
"match": "\*"  
"mapping": { "type": "float" },  
"match\_mapping\_type": "float"  
}  
}  
]  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![Christian\_Dahlqvist](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/christian_dahlqvist/32/4617_2.png) [@Christian\_Dahlqvist](https://discuss.elastic.co/u/Christian_Dahlqvist)\
**Post date:** [March 7, 2016, 6:59am UTC](https://discuss.elastic.co/t/template-index-with-dynamic-mapping-to-float/43407/5 "2016-03-07T06:59:56Z")

</div>

As the CSV filter can not convert strings to other types, you will need to use the mutate filter. You can not send a string containing a float to Elasticsearch and get it converted to a float through mappings. If the value is a string in the document it will be mapped as a string in Elasticsearch.

---

<div class="post-metadata">

**Author:** ![LiorK](https://avatars.discourse-cdn.com/v4/letter/l/65b543/32.png) [@LiorK](https://discuss.elastic.co/u/LiorK)\
**Post date:** [March 7, 2016, 12:37pm UTC](https://discuss.elastic.co/t/template-index-with-dynamic-mapping-to-float/43407/6 "2016-03-07T12:37:52Z")

</div>

how i can do dynamic mapping to float?  
logstash getting a field and without mutate to set it as float in the elasticsearch, csv is just the plugin that i used, i can get the field via grok or something else...

how is it working that for string i can say not\_analyzed, it looks for me kind the same  
take this field and treat him like float/double 😄

appreciate your efforts!

---

<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:10pm UTC](https://discuss.elastic.co/t/template-index-with-dynamic-mapping-to-float/43407/7 "2017-07-05T23:10:41Z")

</div>


