# Elasticsearch Features and Practical Usage
📦 No need to lock down a table schema first — the moment you throw JSON at it, your data is usable. An Elasticsearch index is a document-oriented data store built for search and scale from day one.
🏷️ Title: Index / Document-oriented data store
🔗 URL:
📘 Overview
An index is the fundamental unit of storage in Elasticsearch and the level at which you interact with your data. Data is stored one record at a time as JSON "documents," and each document is a set of field key-value pairs plus system metadata such as `_index`, `_id`, and `_version`.
⚙️ How It Works
・Your actual data lives in the `_source` field, while `_index` (owning index), `_id` (unique ID), and `_version` are system-managed metadata.
・A "mapping" defines each field's type and how it is indexed and queried. You pick types like `text` (for full-text search), `keyword` (exact match and aggregations), `integer`, and `date`.
・Even without an explicit mapping, "dynamic mapping" infers types from the incoming JSON, so you can add new fields later and still index them with no schema migration.
・Internally, an index is split into "shards" distributed across nodes. Data inside a shard is written as immutable "segments," and replica shards provide redundancy and scale.
・Settings like `index.number_of_shards` (fixed at creation), `index.number_of_replicas` (adjustable later), and `index.refresh_interval` (default 1s) control index behavior.
🛠️ Practical Usage
Indexing a single document is straightforward.
`POST products/_doc/p-1001`
`{ "name": "Wireless earbuds", "price": 8900, "stock": 120, "category": "audio" }`
For large loads, the `_bulk` API batches many operations in one request.
`POST products/_bulk`
`{ "index": { "_id": "p-1001" } }`
`{ "name": "Wireless earbuds", "price": 8900 }`
`{ "index": { "_id": "p-1002" } }`
`{ "name": "USB-C cable", "price": 1200 }`
Adding a brand-new field later (e.g. `sustainability_score`) just works thanks to dynamic mapping.
💡 Use Cases
A classic pattern is modeling an e-commerce product catalog as a `products` index, one product = one JSON document (name, price, stock, category, description). A daily batch loads hundreds of thousands of records via `_bulk`, and you can introduce new attributes without waiting on an RDB schema change.
⚠️ Caveats
・A field's type cannot be changed once set. To change a type you must reindex into a new index.
・Use a regular index for frequently updated documents; use a data stream for append-only time-series data.
・Shard count and size directly affect query speed and cluster stability. Avoid huge numbers of tiny shards and aim for sensible shard sizing.
#
Elasticsearch# #
DataModeling#