# Long vs Integer

**URL:** <https://discuss.elastic.co/t/long-vs-integer/65967>\
**Category:** Elasticsearch\
**Created:** [November 14, 2016, 11:18am UTC](https://discuss.elastic.co/t/long-vs-integer/65967 "2016-11-14T11:18:39Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sundar\_V](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/sundar_v/32/6928_2.png) [@Sundar\_V](https://discuss.elastic.co/u/Sundar_V)\
**Post date:** [November 14, 2016, 11:18am UTC](https://discuss.elastic.co/t/long-vs-integer/65967/1 "2016-11-14T11:18:39Z")

</div>

Hello

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

From the answer [here](https://discuss.elastic.co/t/integer-size-vs-long-size/10736/2), 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

---

<div class="post-metadata">

**Author:** ![danielmitterdorfer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/danielmitterdorfer/32/110510_2.png) [@danielmitterdorfer](https://discuss.elastic.co/u/danielmitterdorfer)\
**Post date:** [November 14, 2016, 1:25pm UTC](https://discuss.elastic.co/t/long-vs-integer/65967/2 "2016-11-14T13:25:50Z")

</div>

Hi @Sundar_V,

let me quote the [docs](https://www.elastic.co/guide/en/elasticsearch/reference/master/number.html#_which_type_should_i_use):

> 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

---

<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:** [December 12, 2016, 1:26pm UTC](https://discuss.elastic.co/t/long-vs-integer/65967/3 "2016-12-12T13:26:11Z")

</div>

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