0
0
ElasticsearchConceptBeginner · 3 min read

Integer Type in Elasticsearch: Definition and Usage

In Elasticsearch, the integer type is a numeric data type used to store whole numbers without decimals. It supports values from -2,147,483,648 to 2,147,483,647 and is optimized for fast searching and sorting of integer values.
⚙️

How It Works

The integer type in Elasticsearch stores whole numbers within a specific range, similar to how you might count items or track quantities in real life. Imagine you have a list of ages or product counts; these are naturally whole numbers without fractions, so the integer type fits perfectly.

When you index data with an integer field, Elasticsearch stores it in a way that makes searching, sorting, and aggregating very fast. It uses efficient storage and indexing methods tailored for numbers without decimals, which helps your queries run quickly even on large datasets.

💻

Example

This example shows how to define an integer field in an Elasticsearch mapping and index a document with an integer value.

json
{
  "mappings": {
    "properties": {
      "age": {
        "type": "integer"
      }
    }
  }
}

POST /people/_doc/1
{
  "name": "Alice",
  "age": 30
}
Output
{ "_index": "people", "_id": "1", "_version": 1, "result": "created", "_shards": { "total": 2, "successful": 1, "failed": 0 }, "_seq_no": 0, "_primary_term": 1 }
🎯

When to Use

Use the integer type when you need to store whole numbers within the range of -2,147,483,648 to 2,147,483,647. This is common for counts, ages, IDs, or any numeric data without decimals.

For example, you might use integers to store the number of items in stock, user ages, or the number of clicks on a webpage. Choosing the integer type helps Elasticsearch optimize storage and query speed for these values.

Key Points

  • Integer type stores whole numbers without decimals.
  • Supports values from -2,147,483,648 to 2,147,483,647.
  • Optimized for fast searching, sorting, and aggregations.
  • Ideal for counts, ages, IDs, and similar numeric data.

Key Takeaways

The integer type stores whole numbers within a fixed range efficiently.
Use integer fields for numeric data without decimals like counts or ages.
Integer fields improve search and aggregation performance in Elasticsearch.
The valid integer range is from -2,147,483,648 to 2,147,483,647.