Understanding Indices, Documents, Fields, and Data Types
Understanding Indices, Documents, Fields, and Data Types
In the previous lesson, you learned how Elasticsearch distributes data using clusters, nodes, shards, and replicas.
Now that you understand where data is stored, it's time to learn how data is organized inside Elasticsearch.
Imagine you're building an online shopping website.
You need to store information such as:
- Product name
- Brand
- Price
- Category
- Stock quantity
- Customer ratings
How does Elasticsearch organize all of this information?
The answer lies in four important concepts:
- Index
- Document
- Field
- Data Type
These are the building blocks of every Elasticsearch application.
By the end of this lesson, you'll understand:
- How Elasticsearch organizes data.
- The relationship between indices, documents, and fields.
- Different field data types.
- Why choosing the correct data type matters.
Understanding the Hierarchy
Let's compare the school example with Elasticsearch.
School Example | Elasticsearch |
| Filing Cabinet | Index |
| Individual File | Document |
| Information inside File | Fields |
Once you understand this relationship, Elasticsearch becomes much easier to learn.
What is an Index?
An Index is a collection of related documents.
Think of an index as a folder that stores similar information.
Example
An e-commerce application might have several indices.
E-commerce System
├── products
├── customers
├── orders
├── reviews
Each index stores one type of information.
Why Use Multiple Indices?
Suppose everything was stored in one giant index.
Products, customers, reviews, and orders would all be mixed together.
Searching and managing data would become difficult.
Instead, Elasticsearch separates different types of data into different indices.
This improves:
- Organization
- Search performance
- Data management
What is a Document?
A Document is a single record stored inside an index.
Every document describes one object.
For example:
Products Index
Product 1
Product 2
Product 3
Product 4
Each product is stored as its own document.
Example Document
Suppose we want to store information about a laptop.
{
"name": "Dell Inspiron 15",
"brand": "Dell",
"price": 58999,
"category": "Laptop",
"rating": 4.6,
"in_stock": true
}
Everything together forms one document.
What are Fields?
A Field is an individual piece of information inside a document.
Using the previous example:
{
"name": "Dell Inspiron 15",
"brand": "Dell",
"price": 58999,
"category": "Laptop"
}
The fields are:
- name
- brand
- price
- category
Each field stores one specific value.
Relationship Between Index, Document, and Field
Products Index
│
├── Product Document
│ ├── Name
│ ├── Brand
│ ├── Price
│ ├── Rating
│ └── Category
│
├── Product Document
│
└── Product Document
Notice that:
- One index contains many documents.
- One document contains many fields.
What are Data Types?
Every field stores a particular kind of information.
Elasticsearch needs to know what type of data each field contains.
This is called a data type.
Choosing the correct data type helps Elasticsearch:
- Search more accurately.
- Sort results correctly.
- Improve performance.
- Reduce storage usage.
Common Data Types
1. Text
Used for long sentences or paragraphs.
Example:
"This laptop is ideal for students and professionals."
Used for:
- Product descriptions
- Blog articles
- Customer reviews
2. Keyword
Used for exact values.
Example:
Dell
Unlike text, a keyword is not broken into smaller searchable words.
Useful for:
- Brand names
- Product IDs
- Country codes
- Status values
Text vs Keyword
Suppose we store:
Apple iPhone 16
As Text
Searching:
- Apple
- iPhone
- 16
All can match.
As Keyword
Only an exact match works:
Apple iPhone 16
Searching only for Apple will not match the entire keyword value.
3. Integer
Stores whole numbers.
Examples:
15
300
1000
Used for:
- Stock quantity
- Number of orders
- Age
- Quantity
4. Float
Stores decimal numbers.
Examples:
4.7
89.95
12.50
Used for:
- Ratings
- Prices with decimals
- Temperature
- Discounts
5. Boolean
Stores only two values:
true
false
Used for:
- In stock
- Verified account
- Premium user
- Product available
6. Date
Stores dates and time.
Example:
2026-08-06
Used for:
- Order date
- Registration date
- Birth date
- Delivery date
Example Product Document
{
"name": "Gaming Keyboard",
"brand": "Logitech",
"price": 2499.99,
"stock": 120,
"available": true,
"release_date": "2026-08-01"
}
Data Types:
Field | Data Type |
| name | text |
| brand | keyword |
| price | float |
| stock | integer |
| available | boolean |
| release_date | date |
Why Choosing the Correct Data Type Matters
Imagine storing prices as text.
Instead of numbers:
"500"
"200"
"1000"
Sorting may produce incorrect results because text is sorted alphabetically rather than numerically.
Correct numeric data types allow Elasticsearch to sort values properly.
Another Example
Suppose customer ratings are stored as text.
Finding products with ratings greater than 4.5 becomes difficult.
If ratings are stored as float, Elasticsearch can perform numeric comparisons easily.
How Elasticsearch Uses Fields During Search
Suppose a customer searches:
Dell Laptop under ₹60,000
Elasticsearch checks multiple fields:
- Brand
- Product Name
- Price
- Category
It combines the information to find the best matching products.
This is why well-structured fields are important.
Mini Challenge
Imagine you're building a library management system using Elasticsearch.
Create an index named books.
Then design one sample document with the following information:
- Book title
- Author
- Genre
- Price
- Number of pages
- Availability
- Publication date
Finally:
- Identify the fields in your document.
- Choose an appropriate data type for each field.
- Explain why you selected those data types.










