The problem happens with java and python api when the typechecking throws exceptions For example when we use java to read the values mentioned :
test2/lll/1 my_int = 1 class java.lang.String test2/lll/2 my_int = 2 class java.lang.Integer test2/lll/3 my_int = 1.2 class java.lang.Double *So you see the client code will end up doing all kinds of casting* Has anyone got any experience of how to stamp out such problems ? On Friday, August 1, 2014 6:58:54 PM UTC+1, [email protected] wrote: > okay so when I don't have a mapping and I do a GET _mapping it returns > this: > { > "test1": { > "mappings": { > "type2": { > "properties": { > "my_int": { > "type": "long" > } > } > > > Is that not the same as having a mapping? > > Then to check the theory I created a mapping as follows: > PUT test2 > PUT test2/lll/_mapping > { > "properties": { > "my_int": { > "type": "long" > } > } > } > PUT test2/lll/1 > { > "my_int": "1" > } > PUT test2/lll/2 > { > "my_int": 2 > } > PUT test2/lll/3 > { > "my_int": 1.2 > } > GET test2/lll/_search > > And I get the same results. See *bolded* below: > { > "took": 2, > "timed_out": false, > "_shards": { > "total": 5, > "successful": 5, > "failed": 0 > }, > "hits": { > "total": 3, > "max_score": 1, > "hits": [ > { > "_index": "test2", > "_type": "lll", > "_id": "1", > "_score": 1, > "_source": { > * "my_int": "1"* > } > }, > { > "_index": "test2", > "_type": "lll", > "_id": "2", > "_score": 1, > "_source": { > * "my_int": 2* > } > }, > { > "_index": "test2", > "_type": "lll", > "_id": "3", > "_score": 1, > "_source": { > * "my_int": 1.2* > } > } > ] > } > } > > > So you can see above there are three values: a string, an int and a float > all stored in the long value ??? > > Thanks, > > > On Friday, August 1, 2014 4:46:27 PM UTC+1, David Pilato wrote: > >> Did you try to define a mapping for your field? >> >> -- >> *David Pilato* | *Technical Advocate* | *Elasticsearch.com* >> @dadoonet <https://twitter.com/dadoonet> | @elasticsearchfr >> <https://twitter.com/elasticsearchfr> >> >> >> Le 1 août 2014 à 17:25:53, [email protected] ([email protected]) a écrit: >> >> Hi, >> >> This is something I have discovered is happening... if I have a "long" >> type I can still store numbers such as 2, "4" and 1.2 >> >> Then when I retrieve the type is not long but string and float;( >> >> In other words in Java when I examine my values I can have 2 (type long) >> , "4" (type string) , 1.2 (type float) >> >> But if I want to enforce the type at the time of "data entry" can I >> enforce only longs are accepted ? >> >> I mean if I try to index "this is a number" I will get a format exception. >> >> So can I force an exception when I try to index "4" instead of 4? >> >> Or better still can ES convert the "4" to 4 (type long) >> And the 1.2 converted to 1 (type long) >> >> ? >> >> Thanks, >> -- >> You received this message because you are subscribed to the Google Groups >> "elasticsearch" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/elasticsearch/4e489d04-929e-45a2-9268-21b3d03c4e3f%40googlegroups.com >> >> <https://groups.google.com/d/msgid/elasticsearch/4e489d04-929e-45a2-9268-21b3d03c4e3f%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> >> -- You received this message because you are subscribed to the Google Groups "elasticsearch" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/elasticsearch/735c401a-8356-4d6a-9e1e-fe96f629f48b%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
