# Template to store everything in string

**URL:** https://discuss.elastic.co/t/template-to-store-everything-in-string/7299
**Category:** Elasticsearch
**Created:** [April 11, 2012, 3:48pm UTC](https://discuss.elastic.co/t/template-to-store-everything-in-string/7299 "2012-04-11T15:48:36Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![grab](https://avatars.discourse-cdn.com/v4/letter/g/d26b3c/32.png) [@grab](https://discuss.elastic.co/u/grab)
#### Post date: [April 11, 2012, 3:48pm UTC](https://discuss.elastic.co/t/template-to-store-everything-in-string/7299/1 "2012-04-11T15:48:36Z")

</div>

Hi,

I have lots of data which don't have type all thing are string, when i store those data if the first one is a long then another one a string i have a NumberFormatException :

_"nested: NumberFormatException[For input string: "1N+1"]"_

I don't want to change the mapping file cause i have to much cols.

I try to add the following template

$ curl -XPUT '[http://localhost:9200/animal/cat/\_template](http://localhost:9200/animal/cat/_template)'

{  
"TypeName":{  
"dynamic\_templates":[  
{  
"everything\_string":{  
"match\_mapping\_type" : "_",  
"match" : "Something.Another._",  
"mapping":{  
"type":"string"  
}  
}  
}  
]  
}   
}

if i make a GET i have the template

when i add some data i have the template in the head of the results so it added.

i try "match\_mapping\_type" : "long" but i still have the exception.

Thanks.

---

<div class="post-metadata">

### Author: ![grab](https://avatars.discourse-cdn.com/v4/letter/g/d26b3c/32.png) [@grab](https://discuss.elastic.co/u/grab)
#### Post date: [April 15, 2012, 5:59am UTC](https://discuss.elastic.co/t/template-to-store-everything-in-string/7299/2 "2012-04-15T05:59:34Z")

</div>

Hi again,

I try to add numeric\_detection to false but i don't understand where to PUT it :

{  
"tweet" : {  
"numeric\_detection" : true,  
"properties" : {  
"message" : {"type" : "string"}  
}  
}  
}

find it here : [http://www.elasticsearch.org/guide/reference/mapping/root-object-type.html](http://www.elasticsearch.org/guide/reference/mapping/root-object-type.html)

Somebody can tell me if it can solve my issue?

---

<div class="post-metadata">

### Author: ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)
#### Post date: [April 15, 2012, 2:40pm UTC](https://discuss.elastic.co/t/template-to-store-everything-in-string/7299/3 "2012-04-15T14:40:58Z")

</div>

"numeric\_detection" is false by default. So, you don't need to set it to  
false. In order to set it to true, you can "PUT" it into  
/index\_name/type\_name/\_mapping like this:

curl -XPUT localhost:9200/twitter/tweet/\_mapping -d '{  
"tweet" : {  
"numeric\_detection" : true,  
"properties" : {  
"message" : {"type" : "string"}  
}  
}  
}  
'

On Sunday, April 15, 2012 1:59:34 AM UTC-4, grab wrote:

> Hi again,
> 
> I try to add numeric\_detection to false but i don't understand where to PUT  
> it :
> 
> {  
> "tweet" : {  
> "numeric\_detection" : true,  
> "properties" : {  
> "message" : {"type" : "string"}  
> }  
> }  
> }
> 
> find it here :  
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/root-object-type.html)
> 
> Somebody can tell me if it can solve my issue?
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/template-to-store-everything-in-string-tp3902932p3911445.html](http://elasticsearch-users.115913.n3.nabble.com/template-to-store-everything-in-string-tp3902932p3911445.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

### Author: ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)
#### Post date: [April 15, 2012, 2:51pm UTC](https://discuss.elastic.co/t/template-to-store-everything-in-string/7299/4 "2012-04-15T14:51:13Z")

</div>

By the way, "numeric\_detection" doesn't store everything in a string. It  
works other way around - it tries to check if a string field contains  
something that looks like a number and if it does, it maps this field to a  
number.

On Sunday, April 15, 2012 10:40:58 AM UTC-4, Igor Motov wrote:

> "numeric\_detection" is false by default. So, you don't need to set it to  
> false. In order to set it to true, you can "PUT" it into  
> /index\_name/type\_name/\_mapping like this:
> 
> curl -XPUT localhost:9200/twitter/tweet/\_mapping -d '{  
> "tweet" : {  
> "numeric\_detection" : true,  
> "properties" : {  
> "message" : {"type" : "string"}  
> }  
> }  
> }  
> '
> 
> On Sunday, April 15, 2012 1:59:34 AM UTC-4, grab wrote:
> 
> > Hi again,
> > 
> > I try to add numeric\_detection to false but i don't understand where to  
> > PUT  
> > it :
> > 
> > {  
> > "tweet" : {  
> > "numeric\_detection" : true,  
> > "properties" : {  
> > "message" : {"type" : "string"}  
> > }  
> > }  
> > }
> > 
> > find it here :  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/root-object-type.html)
> > 
> > Somebody can tell me if it can solve my issue?
> > 
> > --  
> > View this message in context:  
> > [http://elasticsearch-users.115913.n3.nabble.com/template-to-store-everything-in-string-tp3902932p3911445.html](http://elasticsearch-users.115913.n3.nabble.com/template-to-store-everything-in-string-tp3902932p3911445.html)  
> > Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

### Author: ![grab](https://avatars.discourse-cdn.com/v4/letter/g/d26b3c/32.png) [@grab](https://discuss.elastic.co/u/grab)
#### Post date: [April 16, 2012, 5:51am UTC](https://discuss.elastic.co/t/template-to-store-everything-in-string/7299/5 "2012-04-16T05:51:28Z")

</div>

Hi,

Thanks for the tips.

So there's no solution to store a "match" thing ("data\_in\_string" exemple above) in string?

{  
"element":{  
"name" : "one"  
"code" : 1232  
"location" : {"lon" : 12,2121, "lat" : 4,5656}  
}  
"data\_in\_string":{  
"something" : "in\_string",  
"everything" : "in\_string",  
"number" : "12"  
}  
}

For "element" i want to keep a clean mapping to make sort on number and geo position with location but all thing inside data\_in\_string must be typed "string".

cause i can have "data\_in\_string.number" : "13 umbrellas"

I try the dynamic template but it don't solve my numeric format exception.

By the way, "numeric\_detection" doesn't store everything in a string. It works other way around - it tries to check if a string field contains something that looks like a number and if it does, it maps this field to a number.

On Sunday, April 15, 2012 10:40:58 AM UTC-4, Igor Motov wrote:

> "numeric\_detection" is false by default. So, you don't need to set it to  
> false. In order to set it to true, you can "PUT" it into  
> /index\_name/type\_name/\_mapping like this:
> 
> curl -XPUT localhost:9200/twitter/tweet/\_mapping -d '{  
> "tweet" : {  
> "numeric\_detection" : true,  
> "properties" : {  
> "message" : {"type" : "string"}  
> }  
> }  
> }  
> '
> 
> On Sunday, April 15, 2012 1:59:34 AM UTC-4, grab wrote:
> 
> > Hi again,
> > 
> > I try to add numeric\_detection to false but i don't understand where to  
> > PUT  
> > it :
> > 
> > {  
> > "tweet" : {  
> > "numeric\_detection" : true,  
> > "properties" : {  
> > "message" : {"type" : "string"}  
> > }  
> > }  
> > }
> > 
> > find it here :  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/root-object-type.html)
> > 
> > Somebody can tell me if it can solve my issue?
> > 
> > --  
> > View this message in context:  
> > [http://elasticsearch-users.115913.n3.nabble.com/template-to-store-everything-in-string-tp3902932p3911445.html](http://elasticsearch-users.115913.n3.nabble.com/template-to-store-everything-in-string-tp3902932p3911445.html)  
> > Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<div class="post-metadata">

### Author: ![Igor\_Motov](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/igor_motov/32/45193_2.png) [@Igor\_Motov](https://discuss.elastic.co/u/Igor_Motov)
#### Post date: [April 16, 2012, 1:36pm UTC](https://discuss.elastic.co/t/template-to-store-everything-in-string/7299/6 "2012-04-16T13:36:24Z")

</div>

In your example, data\_in\_string.number will be stored as a string unless  
you set "numeric\_detection" to true. One thing to keep in mind is that once  
elasticsearch assigns a type to a field this type cannot be changed.

On Monday, April 16, 2012 1:51:28 AM UTC-4, grab wrote:

> Hi,
> 
> Thanks for the tips.
> 
> So there's no solution to store a "match" thing ("data\_in\_string" exemple  
> above) in string?
> 
> {  
> "element":{  
> "name" : "one"  
> "code" : 1232  
> "location" : {"lon" : 12,2121, "lat" : 4,5656}  
> }  
> "data\_in\_string":{  
> "something" : "in\_string",  
> "everything" : "in\_string",  
> "number" : "12"  
> }  
> }
> 
> For "element" i want to keep a clean mapping to make sort on number and geo  
> position with location but all thing inside data\_in\_string must be typed  
> "string".
> 
> cause i can have "data\_in\_string.number" : "13 umbrellas"
> 
> I try the dynamic template but it don't solve my numeric format exception.
> 
> Igor Motov-3 wrote
> 
> > By the way, "numeric\_detection" doesn't store everything in a string. It  
> > works other way around - it tries to check if a string field contains  
> > something that looks like a number and if it does, it maps this field to  
> > a  
> > number.
> > 
> > On Sunday, April 15, 2012 10:40:58 AM UTC-4, Igor Motov wrote:
> > 
> > > "numeric\_detection" is false by default. So, you don't need to set it  
> > > to  
> > > false. In order to set it to true, you can "PUT" it into  
> > > /index\_name/type\_name/\_mapping like this:
> > > 
> > > curl -XPUT localhost:9200/twitter/tweet/\_mapping -d '{  
> > > "tweet" : {  
> > > "numeric\_detection" : true,  
> > > "properties" : {  
> > > "message" : {"type" : "string"}  
> > > }  
> > > }  
> > > }  
> > > '
> > > 
> > > On Sunday, April 15, 2012 1:59:34 AM UTC-4, grab wrote:
> > > 
> > > > Hi again,
> > > > 
> > > > I try to add numeric\_detection to false but i don't understand where  
> > > > to  
> > > > PUT  
> > > > it :
> > > > 
> > > > {  
> > > > "tweet" : {  
> > > > "numeric\_detection" : true,  
> > > > "properties" : {  
> > > > "message" : {"type" : "string"}  
> > > > }  
> > > > }  
> > > > }
> > > > 
> > > > find it here :
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/mapping/root-object-type.html)
> 
> > > > Somebody can tell me if it can solve my issue?
> > > > 
> > > > --  
> > > > View this message in context:
> 
> [http://elasticsearch-users.115913.n3.nabble.com/template-to-store-everything-in-string-tp3902932p3911445.html](http://elasticsearch-users.115913.n3.nabble.com/template-to-store-everything-in-string-tp3902932p3911445.html)
> 
> > > > Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).
> 
> --  
> View this message in context:  
> [http://elasticsearch-users.115913.n3.nabble.com/template-to-store-everything-in-string-tp3902932p3913610.html](http://elasticsearch-users.115913.n3.nabble.com/template-to-store-everything-in-string-tp3902932p3913610.html)  
> Sent from the Elasticsearch Users mailing list archive at [Nabble.com](http://Nabble.com).

---

<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:32am UTC](https://discuss.elastic.co/t/template-to-store-everything-in-string/7299/7 "2017-07-06T03:32:27Z")

</div>


