2013-08-29 07:24:34 +08:00
|
|
|
|
[[mapping]]
|
|
|
|
|
= Mapping
|
|
|
|
|
|
|
|
|
|
[partintro]
|
|
|
|
|
--
|
2015-08-06 23:24:29 +08:00
|
|
|
|
|
|
|
|
|
Mapping is the process of defining how a document, and the fields it contains,
|
2021-01-12 01:31:26 +08:00
|
|
|
|
are stored and indexed.
|
|
|
|
|
|
|
|
|
|
Each document is a collection of fields, which each have their own
|
|
|
|
|
<<mapping-types,data type>>. When mapping your data, you create a mapping
|
|
|
|
|
definition, which contains a list of fields that are pertinent to the document.
|
|
|
|
|
A mapping definition also includes <<mapping-fields,metadata fields>>, like the
|
|
|
|
|
`_source` field, which customize how a document's associated metadata is
|
|
|
|
|
handled.
|
|
|
|
|
|
|
|
|
|
Use _dynamic mapping_ and _explicit mapping_ to define your data. Each method
|
|
|
|
|
provides different benefits based on where you are in your data journey. For
|
|
|
|
|
example, explicitly map fields where you don't want to use the defaults, or to
|
|
|
|
|
gain greater control over which fields are created. You can then allow {es} to
|
|
|
|
|
add other fields dynamically.
|
|
|
|
|
|
|
|
|
|
NOTE: Before 7.0.0, the mapping definition included a type name.
|
|
|
|
|
{es} 7.0.0 and later no longer accept a _default_ mapping. See <<removal-of-types>>.
|
|
|
|
|
|
|
|
|
|
.Experiment with mapping options
|
|
|
|
|
****
|
|
|
|
|
<<runtime-search-request,Define runtime fields in a search request>> to
|
|
|
|
|
experiment with different mapping options, and also fix mistakes in your index
|
|
|
|
|
mapping values by overriding values in the mapping during the search request.
|
|
|
|
|
****
|
2015-08-06 23:24:29 +08:00
|
|
|
|
|
2021-01-12 01:31:26 +08:00
|
|
|
|
[discrete]
|
|
|
|
|
[[mapping-dynamic]]
|
|
|
|
|
== Dynamic mapping
|
|
|
|
|
<<dynamic-field-mapping,Dynamic mapping>> allows you to experiment with
|
|
|
|
|
and explore data when you’re just getting started. {es} adds new fields
|
|
|
|
|
automatically, just by indexing a document. You can add fields to the top-level
|
|
|
|
|
mapping, and to inner <<object,`object`>> and <<nested,`nested`>> fields.
|
2015-08-06 23:24:29 +08:00
|
|
|
|
|
2021-01-12 01:31:26 +08:00
|
|
|
|
Use <<dynamic-templates,dynamic templates>> to define custom mappings that are
|
2021-01-12 02:50:06 +08:00
|
|
|
|
applied to dynamically added fields based on the matching condition.
|
2015-08-06 23:24:29 +08:00
|
|
|
|
|
2021-01-12 01:31:26 +08:00
|
|
|
|
[discrete]
|
|
|
|
|
[[mapping-explicit]]
|
|
|
|
|
== Explicit mapping
|
|
|
|
|
<<explicit-mapping,Explicit mapping>> allows you to precisely choose how to
|
|
|
|
|
define the mapping definition, such as:
|
|
|
|
|
|
|
|
|
|
* Which string fields should be treated as full text fields.
|
|
|
|
|
* Which fields contain numbers, dates, or geolocations.
|
|
|
|
|
* The <<mapping-date-format,format>> of date values.
|
|
|
|
|
* Custom rules to control the mapping for
|
|
|
|
|
<<dynamic-mapping,dynamically added fields>>.
|
2015-08-06 23:24:29 +08:00
|
|
|
|
|
2021-01-12 02:50:06 +08:00
|
|
|
|
Use <<runtime-mapping-fields,runtime fields>> to make schema changes without
|
|
|
|
|
reindexing. You can use runtime fields in conjunction with indexed fields to
|
|
|
|
|
balance resource usage and performance. Your index will be smaller, but with
|
|
|
|
|
slower search performance.
|
2013-08-29 07:24:34 +08:00
|
|
|
|
|
2020-07-23 23:48:22 +08:00
|
|
|
|
[discrete]
|
2020-12-10 06:54:58 +08:00
|
|
|
|
[[mapping-limit-settings]]
|
|
|
|
|
== Settings to prevent mapping explosion
|
|
|
|
|
Defining too many fields in an index can lead to a mapping explosion, which can
|
|
|
|
|
cause out of memory errors and difficult situations to recover from.
|
2020-05-20 01:40:26 +08:00
|
|
|
|
|
|
|
|
|
Consider a situation where every new document inserted
|
|
|
|
|
introduces new fields, such as with <<dynamic-mapping,dynamic mapping>>.
|
|
|
|
|
Each new field is added to the index mapping, which can become a
|
2017-07-14 15:47:41 +08:00
|
|
|
|
problem as the mapping grows.
|
2020-05-20 01:40:26 +08:00
|
|
|
|
|
2020-12-10 06:54:58 +08:00
|
|
|
|
Use the <<mapping-settings-limit,mapping limit settings>> to limit the number
|
|
|
|
|
of field mappings (created manually or dynamically) and prevent documents from
|
|
|
|
|
causing a mapping explosion.
|
|
|
|
|
|
2015-08-06 23:24:29 +08:00
|
|
|
|
--
|
|
|
|
|
|
2021-01-12 01:31:26 +08:00
|
|
|
|
include::mapping/dynamic-mapping.asciidoc[]
|
2020-12-10 06:54:58 +08:00
|
|
|
|
|
2021-01-12 01:31:26 +08:00
|
|
|
|
include::mapping/explicit-mapping.asciidoc[]
|
2013-08-29 07:24:34 +08:00
|
|
|
|
|
2020-12-10 06:54:58 +08:00
|
|
|
|
include::mapping/runtime.asciidoc[]
|
|
|
|
|
|
2021-01-12 01:31:26 +08:00
|
|
|
|
include::mapping/types.asciidoc[]
|
|
|
|
|
|
2015-08-06 23:24:29 +08:00
|
|
|
|
include::mapping/fields.asciidoc[]
|
|
|
|
|
|
|
|
|
|
include::mapping/params.asciidoc[]
|
2013-08-29 07:24:34 +08:00
|
|
|
|
|
2021-01-12 01:31:26 +08:00
|
|
|
|
include::mapping/mapping-settings-limit.asciidoc[]
|
|
|
|
|
|
|
|
|
|
include::mapping/removal_of_types.asciidoc[]
|