Template to store everything in string


(grab) #1

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'

{
"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.


(grab) #2

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

Somebody can tell me if it can solve my issue?


(Igor Motov) #3

"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 :
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
Sent from the ElasticSearch Users mailing list archive at Nabble.com.


(Igor Motov) #4

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 :
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
Sent from the ElasticSearch Users mailing list archive at Nabble.com.


(grab) #5

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 :
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
Sent from the ElasticSearch Users mailing list archive at Nabble.com.


(Igor Motov) #6

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 :

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

Sent from the ElasticSearch Users mailing list archive at Nabble.com.

--
View this message in context:
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.


(system) #7