_id within its index, a set of user-defined fields, and a collection of metadata fields that Elasticsearch manages automatically (such as _index, _id, and _source).
Indexing a document
You can store a document using thePOST /<index>/_doc API (Elasticsearch generates an _id) or PUT /<index>/_doc/<id> when you want to supply your own identifier:
_id and the version number of the newly created document.
What is a mapping?
A mapping defines the schema of an index: which fields exist, what data type each field holds, and how each field should be indexed and stored. Mappings are analogous to a schema definition in a relational database, but they are more flexible — you can add new fields at any time without downtime. You define a mapping inside themappings.properties object when creating an index:
Dynamic vs. explicit mapping
Elasticsearch supports two approaches to mapping, and you can combine them within the same index.- Dynamic mapping
- Explicit mapping
When you index a document into an index that has no mapping for a field — or into an index that does not yet exist — Elasticsearch automatically infers a type and adds the field to the mapping. This is called dynamic mapping.For example, if you index a document with a
price field containing 49.99, Elasticsearch maps it as float. A field containing "hello" is mapped as both text (for full-text search) and keyword (for aggregations and sorting) via a multi-field.Dynamic mapping is convenient for exploration and prototyping, but it can lead to unintended field types in production. You can also define dynamic templates to control how new fields are mapped automatically.The
dynamic setting on an index controls behavior for unmapped fields. Set it to "strict" to reject documents that contain unknown fields, "runtime" to map new fields as runtime fields, or false to ignore unmapped fields (they are stored in _source but not indexed). The default is true (dynamic mapping enabled).Field data types
Elasticsearch provides a rich set of field types grouped by category. Each type determines how values are indexed, stored, and searched.Common types
Common types
These are the types you will use most often for everyday data.
A
| Type | Description |
|---|---|
text | Analyzed, unstructured text. Tokenized and indexed for full-text search. Not suitable for sorting or aggregations. |
keyword | Exact-value strings. Used for filtering, sorting, and aggregations. Not analyzed. |
boolean | true and false values. |
integer / long | Signed 32-bit and 64-bit integers. |
float / double | 32-bit and 64-bit IEEE 754 floating-point numbers. |
date | Date and datetime values. Accepts a configurable format (ISO 8601 by default). |
binary | Binary data encoded as a Base64 string. Not indexed by default. |
alias | Defines an alternate name for an existing field without duplicating data. |
string field commonly needs both full-text search and exact filtering. Use a multi-field to achieve both:Objects and relational types
Objects and relational types
Use these types when your documents contain nested JSON structures or when you need to model relationships between documents.
| Type | Description |
|---|---|
object | A JSON object. Sub-fields are flattened into the parent document at index time. |
nested | A JSON object whose sub-fields maintain their relationship. Required when you need to query individual objects within an array independently. |
flattened | An entire JSON object mapped as a single field. Useful for objects with arbitrary or unpredictable keys. |
join | Models a parent/child relationship between documents in the same index. |
Structured data types
Structured data types
These types are suited for structured values where you need range queries, IP lookups, or version comparisons.
| Type | Description |
|---|---|
integer_range, float_range, date_range, ip_range | Represent a range of values rather than a single value. Support range overlap queries. |
ip | IPv4 and IPv6 addresses. Supports CIDR notation in queries. |
version | Software version strings following Semantic Versioning (semver) precedence rules. |
Text search types
Text search types
Beyond the core
text type, Elasticsearch provides specialized types for advanced search scenarios.| Type | Description |
|---|---|
text | Standard analyzed text for full-text search. |
match_only_text | A space-optimized variant of text that trades positional scoring for reduced storage. |
search_as_you_type | Optimized for prefix and infix matching to power as-you-type search UIs. |
semantic_text | Stores text and its inferred embeddings for semantic search. Requires an inference endpoint. |
completion | Optimized for low-latency autocomplete suggestions via the Suggest API. |
token_count | Stores the number of tokens produced by analyzing a text value. |
Document ranking types
Document ranking types
These types are used for vector search and learning-to-rank scenarios.
Example
| Type | Description |
|---|---|
dense_vector | Stores a fixed-length array of float values. Used for k-nearest neighbor (kNN) vector search. Requires specifying dims (number of dimensions). |
sparse_vector | Stores sparse float vectors. Used with models that produce sparse representations such as ELSER. |
rank_feature | A single numeric feature used to boost scores at query time via the rank_feature query. |
rank_features | A map of numeric features used to boost scores at query time. |
dense_vector mapping for a 384-dimension embedding model:Spatial data types
Spatial data types
Use these types to store and query geographic or cartesian coordinates.
Example
| Type | Description |
|---|---|
geo_point | A latitude/longitude point on the Earth’s surface. Supports distance queries, bounding box filters, and geo-aggregations. |
geo_shape | Complex geographic shapes such as polygons, linestrings, and multi-geometries. |
point | An arbitrary point in a 2D Cartesian coordinate system (not geographic). |
shape | Arbitrary Cartesian geometries. |
geo_point value formats (all equivalent):Aggregate metric types
Aggregate metric types
These types store pre-aggregated data, making them useful for rollup indices and summary statistics.
| Type | Description |
|---|---|
aggregate_metric_double | Stores pre-aggregated values (min, max, sum, value_count) for a metric. Aggregation queries operate on these pre-computed values. |
histogram | Stores pre-aggregated numerical data in the form of a T-Digest or HDR histogram for use with percentile and histogram aggregations. |
Mapping parameters
Beyond thetype, field mappings accept parameters that control indexing behavior. The index parameter is one of the most important:
"index": false stores the field value in _source but does not build an inverted index for it, saving disk space when you only need to retrieve the value but never search on it.
