Datatype long behaving odd


(narinder.izap) #1

hey shay,
I am confused with the long datatype.

I have a document of type "posts":

{
id: int
title:string
owner_id:int
can_view: array
{
type:long
}
}

Here in this "can_view" attributes was saving the ids of the users who can
view the posts,and data which was stored was like :

{
id: 2343
title:"my post for all"
owner_id:123
can_view: array
[
2324,
2343,
"7654"
]
}

like here some ids are stored as int and some as string, and it was
working fine. I did'nt get how was this happening. as java is strict
language,so it should not allow the int saved as string(int number with
quotes).

and now i need to change the data, instead of saving the ids, i have to
store the names, but its giving the exception

"MapperParsingException[Failed to parse [can_see]]; nested:
NumberFormatException[For input string: "narinder"]; "

*
*
And moreover we are having a plan to store mixed datatypes in the single
level array, is that possible?? please help me through.

Thanks


(Shay Banon) #2

Once a field is of numeric type (int or long for example, which differ on
the number of bytes used to represent them), then it will also support
providing a "string" value that can be parsed to the numeric value. The
first data type of the document introduced will be used if its not mapped
explicitly. Once the data type of a field is set, it can't be changed.

If you have a field that has both numeric and text values, then it can be a
string type.

On Mon, May 14, 2012 at 1:51 PM, Narinder Kaur narinder.kaur@izap.inwrote:

hey shay,
I am confused with the long datatype.

I have a document of type "posts":

{
id: int
title:string
owner_id:int
can_view: array
{
type:long
}
}

Here in this "can_view" attributes was saving the ids of the users who can
view the posts,and data which was stored was like :

{
id: 2343
title:"my post for all"
owner_id:123
can_view: array
[
2324,
2343,
"7654"
]
}

like here some ids are stored as int and some as string, and it was
working fine. I did'nt get how was this happening. as java is strict
language,so it should not allow the int saved as string(int number with
quotes).

and now i need to change the data, instead of saving the ids, i have to
store the names, but its giving the exception

"MapperParsingException[Failed to parse [can_see]]; nested:
NumberFormatException[For input string: "narinder"]; "

*
*
And moreover we are having a plan to store mixed datatypes in the single
level array, is that possible?? please help me through.

Thanks


(system) #3