Mapping

Learn about the process of mapping and its types in Elasticsearch.

Overview

In ElasticSearch, mapping is the process of defining how a document and its fields are indexed and stored. It’s similar to a table description in a relational database or a schema definition in a document store database (NoSQL). Mapping can be defined using the following:

  • Dynamic mapping
  • Explicit mapping

Dynamic mapping

Dynamic mapping is a feature in Elasticsearch that automatically detects the data type of a field and creates the mapping for it. More simply, if a field is not present in the mapping, Elasticsearch automatically adds the field to the mapping with the appropriate data type.

When Elasticsearch ingests a JSON object, it will analyze the keys and values within the object to determine their data types. It can recognize common data types such as numbers, strings, and dates.

The following illustration shows JSON data and how Elasticsearch identifies the type of its fields.

Press + to interact
Elasticsearch identifying JSON data types
Elasticsearch identifying JSON data types

After identifying JSON types, Elasticsearch uses the rules in the following table to determine how to map data types for each field.

JSON Data Type

Specifications

Elasticsearch Mapping

boolean

-

boolean

long 

-

long

double

-

double

object

-

object

array

Depends on the first non-null value in the array to determine its type

array

string

Strings that contain dates such as "2022-01-01" will be mapped as the date datatype.

date

string

Strings that contain numbers such as "132" will be mapped as the long datatype.

long

string

Strings that contain normal text such as "Fifa worldcup 2022" will be mapped as the text and keyworddata types.

text with a keyword sub-field

Note: More details about the data types Elasticsearch provides ...