Long vs Integer


(Sundar V) #1

Hello

Is there an advantage or disadvantage is choosing a variable as integer vs long.

From the answer here, it seems that even if I choose integer, the variable internal to ES is still long.

So the only advantage that I see is type checking. Is there any other advantage in terms of storage or performance in choosing int over long or vice-versa


(Daniel Mitterdorfer) #2

Hi @Sundar_V,

let me quote the docs :

you should pick the smallest type which is enough for your use-case. This will
help indexing and searching be more efficient. Note however that given that
storage is optimized based on the actual values that are stored, picking one
type over another one will have no impact on storage requirements.

I think it also makes sense from a semantic perspective to use the smallest possible type. If you are dealing with people and want to capture their age in years it's better to use a short but if you are into astrophysics you might choose a long to represent the age of stars (in years). This already codifies your expectation about valid ranges in the type system.

Daniel


(system) #3

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.